I cannot understand what am I doing wrong. I want to unmarshall an xml using JAXB, but i noticed that setter method wasn't called. I am using Java 1.5. Getters and Setters in Attribute.java class - work correctly, but in Configuration.java class - Setter method doesn't call. Can you please show me where am I wrong?
@XmlRootElement(name="configuration")
@XmlAccessorType(XmlAccessType.NONE)
public class Configuration {
public List< Configuration> getItems() {
return new ArrayList<Attribute>(getMap().values());
}
@XmlElement(name="attributes")
public void setItems(List<Attribute> attributes) {
getMap().clear();
for (Attribute attribute : attributes) {
getMap().put(attribute.getName(), attribute);
}
}
private Map<String, Attribute> map;
public Map<String, Attribute> getMap() {
if (map == null) {
map = new HashMap<String, Attribute>();
}
return map;
}
}
My XML looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<attributes name="some_name" type="calculation" value="select ? from dual" priority="0"/>
</configuration>
If a List
is returned from the getter a JAXB impl will use that to add the collection items to instead of creating a new one and setting it via the setter.
The purpose of this is to give you the chance to initialize the implementation of List
that best fits your domain model.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With