users@jersey.java.net

RE: [Jersey] Different format in XML and JSON

From: KARR, DAVID (ATTCINW) <"KARR,>
Date: Wed, 7 Oct 2009 07:55:13 -0700

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