0

I want to Create json array like this to use jquery datatable plugin with java servlet

{
  "data": [
    {
      "name": "Tiger Nixon",
      "position": "System Architect",
      "salary": "$320,800",
      "start_date": "2011/04/25",
      "office": "Edinburgh",
      "extn": "5421"
    },
    {
      "name": "Garrett Winters",
      "position": "Accountant",
      "salary": "$170,750",
      "start_date": "2011/07/25",
      "office": "Tokyo",
      "extn": "8422"
    }
  ]
}
0

2 Answers 2

2

its Very easy actually. Use Google gson.jar Either you download From Here Download Google GSON Jar OR add dependencies(if Your Project is Maven) to your pom.xml

<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.2.2</version>
</dependency>

and try this Link GSON Serializer Example

Note :- This is just a reference code. You can Implement at your own way as per your Need. Thank You

Sign up to request clarification or add additional context in comments.

Comments

0

Create a POJO which represents your JSON object. Top object containing list of second object. Use jackson or xstream to marshal Java object into Json and write the json string onto servlet response.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.