From b2b44a3b1e90f3fca3d85ab80d4c6a572eb7e8bb Mon Sep 17 00:00:00 2001 From: Eric Schoonover Date: Fri, 20 Dec 2013 14:07:35 -0800 Subject: [PATCH] added a test that repos issue #86 - https://github.com/FasterXML/jackson-dataformat-xml/issues/86 - can not deserialize unwrapped list when @JacksonXmlProperty.localName matches JacksonXmlRootElement.localName - related: http://stackoverflow.com/questions/20673153/can-not-deserialize-unwrapped-list-when-jacksonxmlproperty-localname-matches-j --- .../dataformat/xml/unwrapped/TestIssue86.java | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/test/java/com/fasterxml/jackson/dataformat/xml/unwrapped/TestIssue86.java diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/unwrapped/TestIssue86.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/unwrapped/TestIssue86.java new file mode 100644 index 000000000..3b19910f9 --- /dev/null +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/unwrapped/TestIssue86.java @@ -0,0 +1,96 @@ +package com.fasterxml.jackson.dataformat.xml.unwrapped; + +import java.util.Arrays; +import java.util.List; + +import junit.framework.Assert; + +import org.junit.Test; + +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.dataformat.xml.XmlMapper; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; + +public class TestIssue86 { + + @Test + public void deserializeUnwrappedListWhenLocalNameForRootElementAndXmlPropertyMatch() throws Exception { + final String source = + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + final Issue86 before = new Issue86( + "0", + Arrays.asList( + new Issue86( + "0.1", + Arrays.asList( + new Issue86( + "0.1.1", + null))), + new Issue86( + "0.2", + null), + new Issue86( + "0.3", + Arrays.asList( + new Issue86( + "0.3.1", + null))))); + + final XmlMapper mapper = new XmlMapper(); + mapper.setSerializationInclusion(Include.NON_NULL); + + final String xml = mapper.writeValueAsString(before); + Assert.assertEquals(source, xml); + + final Issue86 after = mapper.readValue(xml, Issue86.class); + Assert.assertEquals(before, after); + } + + @JacksonXmlRootElement(localName = "test") + public static class Issue86 { + + @JacksonXmlProperty(localName = "id", isAttribute = true) + private String id; + + @JacksonXmlElementWrapper(useWrapping = false) + @JacksonXmlProperty(localName = "test") + private List children; + + public Issue86() {} + + public Issue86(final String id, final List children) { + this.id = id; + this.children = children; + } + + @Override + public boolean equals(final Object other) { + if (other == null) { + return false; + } + + if (other == this) { + return true; + } + + if (!(other instanceof Issue86)) { + return false; + } + + final Issue86 otherIssue86 = (Issue86) other; + return otherIssue86.id.equals(id) && otherIssue86.children.equals(children); + } + } + +}