users@jaxb.java.net

RE: How to make simple change in XML mapping of list

From: KARR, DAVID (ATTCINW) <"KARR,>
Date: Fri, 11 Sep 2009 10:47:41 -0700

> -----Original Message-----
> From: KARR, DAVID (ATTCINW)
>
> I'm using CXF 2.2.3 in WebLogic 10MP1 and JDK 1.5.
>
> I have a simple class as follows:
>
> @XmlRootElement(name = "Item")
> public class Item {
> private String id;
> private String title;
> private String description;
> private List<String> features = new ArrayList<String>();
>
> // ... getters/setters
>
> @XmlElementWrapper
> public List<String> getFeatures() { return features; }
>
> public void addFeature(String feature) { getFeatures().add(feature);
> }
> }
>
> This marshals like this:
>
> <Item>
> <description>def</description>
> <features>
> <features>123</features>
> <features>456</features>
> </features>
> <id>1</id>
> <title>abc</title>
> </Item>
>
> Is there something simple I can do to make it do this instead
> ("feature"
> instead of "features" for the list elements)?:
>
> <Item>
> <description>def</description>
> <features>
> <feature>123</feature>
> <feature>456</feature>
> </features>
> <id>1</id>
> <title>abc</title>
> </Item>

Never mind. I figured it out. Adding an '_at_XmlElement(name =
"feature")' after the other annotation did it.