users@jersey.java.net

[Jersey] Re: how to rename XmlRootElement in JSON

From: Maxrunner <joao.rossa_at_gmail.com>
Date: Mon, 30 May 2011 11:33:20 -0700 (PDT)

*"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. "*

If you're using a list wrapper class then the name of the variable
containing the list is the one used. But then it also adds the wrapper class
itself.

*"(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. "*

The fix jakub is doing seems to be the more straightforward option. That way
i can hide the root element according to the object mapper. Dont you agree?,
i dont really understand how to use mix in annotations, the jackson
documentation isnt really that explicit,

*"(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. "*

where do i do this?in the context resolver class?

regards,

On Mon, May 30, 2011 at 7:14 PM, Cowtowncoder [via Jersey] <
ml-node+6420107-733476264-73314_at_n2.nabble.com> wrote:

> On Mon, May 30, 2011 at 6:24 AM, Maxrunner <[hidden email]<http://user/SendEmail.jtp?type=node&node=6420107&i=0>>
> 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 +-
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://jersey.576304.n2.nabble.com/how-to-rename-XmlRootElement-in-JSON-tp6173292p6420107.html
> To unsubscribe from how to rename XmlRootElement in JSON, click here<http://jersey.576304.n2.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=6173292&code=am9hby5yb3NzYUBnbWFpbC5jb218NjE3MzI5MnwyMDYzODA1MDkw>.
>
>


--
View this message in context: http://jersey.576304.n2.nabble.com/how-to-rename-XmlRootElement-in-JSON-tp6173292p6420153.html
Sent from the Jersey mailing list archive at Nabble.com.