users@jersey.java.net

Re: [Jersey] Different format in XML and JSON

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 07 Oct 2009 22:49:32 +0200

On Oct 7, 2009, at 5:55 PM, bea wrote:

> Thanks! That's almost perfect. Using the XMLElementWrapper
> annotation the resulting XML document is what I expected.
>
> The problem is in the JSON output:
>
> .......
> "groups" : {
> "group" : [ "group1", "group2" ]
> }
> ........
>
> I don't want the tag "group". I think it'll be difficult getting
> different formats.
>

Yes, in that case i would recommend using Jackson.

Paul.

>
>
> On Wed, Oct 7, 2009 at 4:55 PM, KARR, DAVID (ATTCINW)
> <dk068x_at_att.com> wrote:
> You should be able to preface either the getter or the field
> (depending on what your XmlAccessType is set to) with annotations
> like the following:
>
>
> @XmlElementWrapper(name = "groups")
>
> @XmlElement(name = "group")
>
>
> From: bea [mailto:beaotx_at_gmail.com]
> Sent: Wednesday, October 07, 2009 7:06 AM
> To: users_at_jersey.dev.java.net
> Subject: [Jersey] Different format in XML and JSON
>
>
> Hi,
>
>
> I use a JAXBContextResolver with natural JSON notation. I've an
> object with a Collection called "groups". In JSON I get the
> following result:
>
> { ... "groups":["group1", "group2", "group3"] ... }
>
>
> But in XML format I get:
>
> ....
> <groups>group1</groups>
> <groups>group2</groups>
> <groups>group3</groups>
> ....
>
>
> I'd like to know if it's possible to modify only the XML ouput in
> this way:
>
> <groups>
> <group>group1</group>
> <group>group2</group>
> <group>group3</group>
> </groups>
>
> keeping the same JSON output.
>
> Cheers
>
>
>