users@jersey.java.net

[Jersey] Re: JSON serialization to object lists instead of array

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Mon, 11 Jul 2011 18:36:33 +0200

Hi Michael,

Not really sure how to achieve that.

Do you use JAXB beans or Jackson when generating JSON?

For JAXB, it should be possible to use XmlAdapter somehow.

For Jackson, you would better ask at Jackson mailing list.

~Jakub


On 07/10/2011 12:51 PM, Michael Justin wrote:
> Is it possible to configure the JSON representation in Jersey to
> generate object lists instead of arrays like in this example? (found
> [here][1])
>
> {
> "accomodations" : [
> {
> "accomodation" : {
> "name": "...",
> "category": "couch",
> "uri": "http://example.org/accomodations/accomodation_1"
> }
> },
> {
> "accomodation": {
> "name": "...",
> "category": "room",
> "uri": "http://example.org/accomodations/accomodation_2"
> }
> }
> ]
> }
>
> If I try using a `List<Accomodation>`, the result looks like
>
>
> {
> "accomodations" : [
> {
> "name": "...",
> "category": "couch",
> "uri": "http://example.org/accomodations/accomodation_1"
> },
> {
> "name": "...",
> "category": "room",
> "uri": "http://example.org/accomodations/accomodation_2"
> }
> ]
> }
>
> [1]:
> http://stackoverflow.com/questions/2737809/restful-api-how-to-model-json-representation/2739537#2739537
>
> Regards
> Michael Justin
>