users@jersey.java.net

[Jersey] Re: JSON document -> JAXB class ?

From: Arun Gupta <arun.p.gupta_at_oracle.com>
Date: Tue, 10 Jan 2012 09:11:37 -0800

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