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"
    }
  ]
}
Cœur
  • 37,241
  • 25
  • 195
  • 267

2 Answers2

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

Vikrant Kashyap
  • 6,398
  • 3
  • 32
  • 52
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.

Bhushan Bhangale
  • 10,921
  • 5
  • 43
  • 71