users@jaxb.java.net

How to make simple change in XML mapping of list

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

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>