users@jersey.java.net

[Jersey] Re: how to rename XmlRootElement in JSON

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Mon, 30 May 2011 11:14:01 -0700

On Mon, May 30, 2011 at 6:24 AM, Maxrunner <joao.rossa_at_gmail.com> wrote:
> Well that's only a way to solve my issue. I just want tho change the List
> type name to one my own, like in here:

I have mentioned this multiple times, but wrapping only applies to the
actual type of the value. In this case it is the List type; and
annotation thereby MUST BE for that type.
Whatever types of values within List have is irrelevant and will not
be used under any circumstances.

To get wrapping you want, you have couple of choices:

(a) Add @XmlRootElement annotation to relevant List type; either by
sub-classing as a new class with annotation; or by using mix-in
annotations to associate annotation.
(b) Implement custom AnnotationIntrospector (extending either
JacksonAnnotationIntrospector or JaxbAnnotationIntrospector) and
override 'findRootName' method; in this case you are free to use
whatever logic you want to associate wrapper name.

I suggest you try out one of these approaches as they would solve your
problem, as long as correct ObjectMapper is being used.

-+ Tatu +-