users@jersey.java.net

[Jersey] POJO mapping feature -> natural

From: Benjamin Turner <bgt_at_google.com>
Date: Tue, 22 Feb 2011 16:57:59 -0500

Hi, I'm developing a servlet application using Jersey. I'm still learning
the platform, and have enabled the "FEATURE_POJO_MAPPING" init parameter to
easily produce and consume JSON, but I'd like for it to use the "natural"
notation. Is there another parameter that would allow me to do that in a
line or two of code, or will I need to write a custom provider for this?
 Thanks.

In case a concrete example would help, I have a class "FakeUser" with 3
properties, and my @GET method returns an array of two of these objects.
 When I load the servlet in my browser, I get:

{"fakeUser":[{"id":"1","name":"Ben","lastLoaded":"0"},{"id":"2","name":"Marc","lastLoaded":"0"}]}

...when what I'd like to get is:


[{"id":1,"name":"Ben","lastLoaded":0},{"id":2,"name":"Marc","lastLoaded":0}]

I'm hoping to keep the implementation as simple as possible, so I'd love to
make this adjustment - really just switching from "mapped" to "natural"
notation - without having to write a whole provider of my own. Thanks
again.

-Ben Turner