The endpoint is returning the response as:
[
{ },
{ },
{ }
]
Notice, this is an array, not an array nested in an object. Any
suggestions on how the client-side POJO could look like ?
List<Pojo> or Pojo[] from a JAX-RS endpoint return JSON like:
{"pojo"
:
[{"id":"10","text":"some text"},{"id":"20","text":"more text"}]
}
-Arun
On 1/10/12 9:16 AM, John Yeary wrote:
> Hello Arun,
>
> That is very interesting. I would like to know what your solution
> looks like since I have a similar problem that I have not had the time
> to look at yet. I guess I should have read your post more carefully
> about the client side.
>
> John
> ____________________________
>
> John Yeary
> ____________________________
>
> <http://javaevangelist.blogspot.com/> <https://twitter.com/jyeary>
> <http://www.youtube.com/johnyeary> <http://www.linkedin.com/in/jyeary>
> <https://plus.google.com/112146428878473069965>
> <http://www.facebook.com/jyeary>
> <http://feeds.feedburner.com/JavaEvangelistJohnYearysBlog>
> <http://netbeans.org/people/84414-jyeary>
> ____________________________
>
> "Far better it is to dare mighty things, to win glorious triumphs,
> even though checkered by failure, than to take rank with those poor
> spirits who neither enjoy much nor suffer much, because they live in
> the gray twilight that knows not victory nor defeat."
> -- Theodore Roosevelt
>
>
>
> On Tue, Jan 10, 2012 at 12:11 PM, Arun Gupta <arun.p.gupta_at_oracle.com
> <mailto:arun.p.gupta_at_oracle.com>> wrote:
>
> Thanks Tatu and John!
>
> I've started hand-crafting the POJO class with @XmlRootElement. My
> question was looking for some utility that can generate this class
> for me by introspecting the JSON response. The service endpoint is
> a well known endpoint and I only need this on the client-side so
> @Produces and @Consumes will not be required.
>
> Seems
>
> On 1/9/12 6:43 PM, John Yeary wrote:
>> There is an automatic mapping using POJO to JSON mapping. The
>> simple act of annotating a class as an @XmlRootElement is
>> sufficient to provide automatic mapping for JSON, and XML with
>> just setting @Produces({MediaType.APPLICATION_JSON}), or
>> @Consumes({MediaType.APPLICATION_JSON}). If you want to change
>> the default provider, or change the JSON mapping to something
>> like BadgerFish you need to change the JSONJAXBContext.
>>
>> I am sure you already saw this, but I will post it anyway.
>>
>> http://jersey.java.net/nonav/documentation/latest/json.html
>>
>> John
>> ____________________________
>>
>> John Yeary
>> ____________________________
>>
>> <http://javaevangelist.blogspot.com/>
>> <https://twitter.com/jyeary> <http://www.youtube.com/johnyeary>
>> <http://www.linkedin.com/in/jyeary>
>> <https://plus.google.com/112146428878473069965>
>> <http://www.facebook.com/jyeary>
>> <http://feeds.feedburner.com/JavaEvangelistJohnYearysBlog>
>> <http://netbeans.org/people/84414-jyeary>
>> ____________________________
>>
>> "Far better it is to dare mighty things, to win glorious
>> triumphs, even though checkered by failure, than to take rank
>> with those poor spirits who neither enjoy much nor suffer much,
>> because they live in the gray twilight that knows not victory nor
>> defeat."
>> -- Theodore Roosevelt
>>
>>
>>
>> On Mon, Jan 9, 2012 at 9:15 PM, Tatu Saloranta
>> <tsaloranta_at_gmail.com <mailto:tsaloranta_at_gmail.com>> wrote:
>>
>> On Mon, Jan 9, 2012 at 6:01 PM, Arun Gupta
>> <arun.p.gupta_at_oracle.com <mailto:arun.p.gupta_at_oracle.com>> wrote:
>> > Jersey Client API has to suck up a relatively complex JSON
>> document from a
>> > REST endpoint. What are my options for mapping this JSON
>> document to a
>> > corresponding JAXB class ?
>>
>> Do you actually need a JAXB (annotated) class? Or just a
>> regular POJO?
>>
>> If POJO, just write it to match structure of JSON -- after
>> all, JSON
>> is object notation, meaning that there is natural correlation
>> between
>> POJO properties, JSON data.
>>
>> And even for JAXB basic POJOs typically work fine;
>> annotations are
>> mostly needed to override default behavior.
>>
>> > Use org.json APIs ? Would be rather time consuming!
>>
>> No there is no need for such extreme measures. :)
>>
>> -+ Tatu +-
>>
>>
>
> --
> http://twitter.com/arungupta
> http://blogs.oracle.com/arungupta
>
>
--
http://twitter.com/arungupta
http://blogs.oracle.com/arungupta