users@jersey.java.net

[Jersey] Re: Controlling JSON to POJO mapping

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Tue, 18 Sep 2012 10:36:38 -0700

On Tue, Sep 18, 2012 at 10:33 AM, Tatu Saloranta <tsaloranta_at_gmail.com> wrote:
> On Tue, Sep 18, 2012 at 5:46 AM, Carsten Byrman <carsten_at_byrman.demon.nl> wrote:
>> Thanks for your time, Mike.
>>
>> So 5.2 of the Jersey User Guide (JAXB Based JSON support) is the way to go -
>> even if the web service only returns JSON (no XML)?
>
> Example given did not actually use any of JAXB, not even annotations,
> so it's bit of a red herring.
> Structure given works as-is with Jackson-based POJO-mapping.

Forgot to mention; since you do need to rename properties (since
external notation uses underscores, not Java camel style), you will
need JAXB or Jackson annotations.

With Jackson it'll be @JsonProperty("first_name"); and with JAXB
@XmlElement or @XmlAttribute.

As to which ones to use: JAXB is an XML-binding framework, and unless
you actually do XML, I don't see much value in choosing JAXB unless
you have specific need. But at the same time, they work just fine for
basic configuration like property renaming.

-+ Tatu +-