users@jersey.java.net

[Jersey] Re: how to rename XmlRootElement in JSON

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Fri, 27 May 2011 09:35:24 -0700

On Fri, May 27, 2011 at 6:47 AM, Jakub Podlesak
<jakub.podlesak_at_oracle.com> wrote:
> Tatu needs to confirm, but i think, you should be able to write and register
> your custom JsonSerializer to change the JSON name for the
> List<OrganicaMobileEntity>.

One thing to note is that while Jackson does support root element
wrapping (SerializationConfig.Feature.WRAP_ROOT_VALUE), it is based on
root value instance type.
And if type happens to be List or Map, that List or Map type must have
@XmlRootElement annotation.
Alternatively it is possible to override
JacksonAnnotationIntrospector.findRootName(annotatedClass) method to
define custom handling.

Aside from that, I personally prefer more explicit handling of
wrapping by just introducing either single-entry Map, or
single-property POJO, instead of relying on other methods for
injecting extra layers. Sometimes more explicit approach is simpler
and works better than magic features.

-+ Tatu +-