Skip to content

@JacksonXmlElementWrapper Conflicting getter/setter definitions for property #27

Open
@n00bman

Description

@n00bman

Hi, I'm using latest release 2.0.1 and I've got a problem with serializing/deserializing xml (everything works fine in JSON).
I'd like to have such a xml: namename

public class WrapperTest {

public static void main(String[] args) throws JsonGenerationException,
        JsonMappingException, IOException {
    ObjectMapper mapper = new XmlMapper();
    Bean bean = new Bean();
    BeanInfo beanInfo = new BeanInfo();
    beanInfo.setName("name");
    BeanInfo beanOther = new BeanInfo();
    beanOther.setName("name");
    bean.setBeanInfo(new BeanInfo[] { beanInfo });
    bean.setBeanOther(new BeanInfo[] { beanOther });
    String output = mapper.writeValueAsString(bean);
    System.out.println(output);
}

@JacksonXmlRootElement(localName = "output")
private static class Bean {
    private BeanInfo[] beanInfo;
    private BeanInfo[] beanOther;

    @JacksonXmlElementWrapper(localName = "beanInfo")
    @JacksonXmlProperty(localName = "item")
    public BeanInfo[] getBeanInfo() {
        return beanInfo;
    }

    @JacksonXmlElementWrapper(localName = "beanInfo")
    public void setBeanInfo(BeanInfo[] beanInfo) {
        this.beanInfo = beanInfo;
    }

    @JacksonXmlElementWrapper(localName = "beanOther")
    @JacksonXmlProperty(localName = "item")
    public BeanInfo[] getBeanOther() {
        return beanOther;
    }
    @JacksonXmlElementWrapper(localName = "beanOther")
    public void setBeanOther(BeanInfo[] beanOther) {
        this.beanOther = beanOther;
    }
}

private static class BeanInfo {
    private String name;

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}

}

This example give getter definition conflict.

If I change

@JacksonXmlElementWrapper(localName = "beanOther")
        @JacksonXmlProperty(localName = "item2")
        public BeanInfo[] getBeanOther() {
}

then all work fine and I've got

<output><beanInfo><item><name>name</name></item></beanInfo><beanOther><item2><name>name</name></item2></beanOther></output>

but if I try to deserialize it then I've got setter definition conflict...

Metadata

Metadata

Assignees

No one assigned

    Labels

    has-failing-testIndicates that there exists a test case (under `failing/`) to reproduce the issuename-collisionIssue related to name collision wrt element/attr or nested lists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions