简体   繁体   中英

JAXB does not call Setter method

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM