JAXB does not call Setter method

I don't understand what I am doing wrong. I want to unmarshall xml using JAXB, but I noticed that the setter method was not called. I am using Java 1.5. Getters and Setters in the Attribute.java class - work correctly, but in the Configuration.java class - the Setter method does not call. Could you show me where I'm going 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>

      

+3


source to share


1 answer


If a is returned from the getter List

, JAXB impl will use that to add the elements to the collection instead of creating a new one and setting it through the installer.



The purpose of this is to give you the ability to initialize the implementation List

that best suits your domain model.

+5


source







All Articles