mardi 5 juillet 2016

how to convert map to json in restful [duplicate]

This question already has an answer here:

In my project i am dynamically generating json and put that into Map<String,Student>() Note:Key is dynamic so my response is printing like below :

"entry": [
        {
          "key": "student1",
          "value": {
            "name":selva
          }
        },
        {
          "key": "student2",
          "value": {
           "name":"kumar"
          }
        }
       ]

But my expected response is :

[
"student1" : {
"name":"kumar"
},
"student2" : {
"name":"selva"
}
]

**My keys are dynamic here...**

How to achiveve the desired result in jersey. pom.xml

<!-- Json dependency -->
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
        </dependency>
<dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-moxy</artifactId>
        </dependency>

Any help will be greatly appreciated!!!!

Aucun commentaire:

Enregistrer un commentaire