Skip to content

Commit 19330ce

Browse files
committed
more testing
1 parent e8a13bb commit 19330ce

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

src/test/java/com/fasterxml/jackson/dataformat/xml/lists/ListDeser469Test.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.*;
44

55
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
6+
import com.fasterxml.jackson.dataformat.xml.JacksonXmlAnnotationIntrospector;
67
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
78
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
89
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
@@ -51,7 +52,7 @@ protected InnerBean2() { }
5152
public InnerBean2(String s) { str2 = s; }
5253
}
5354

54-
public void testIssue469() throws Exception
55+
public void testIssue469WithDefaults() throws Exception
5556
{
5657
// Here we just use default settings (which defaults to wrappers)
5758
final XmlMapper mapper = newMapper();
@@ -93,4 +94,39 @@ public void testIssue469() throws Exception
9394
assertEquals(1, mid.inner2.size());
9495
assertEquals("aaaa", mid.inner2.get(0).str2);
9596
}
97+
98+
static class OuterNoWrappers {
99+
public List<InnerNoWrappers> inner;
100+
}
101+
102+
static class InnerNoWrappers {
103+
@JacksonXmlProperty(isAttribute = true)
104+
public String str;
105+
106+
protected InnerNoWrappers() { }
107+
public InnerNoWrappers(String s) { str = s; }
108+
}
109+
110+
// But alternatively can try setting default to "no wrappers":
111+
public void testIssue469WithNoWrapper() throws Exception
112+
{
113+
final XmlMapper mapper = XmlMapper.builder()
114+
.annotationIntrospector(new JacksonXmlAnnotationIntrospector(false))
115+
.build();
116+
117+
// First: check round-trip
118+
{
119+
OuterNoWrappers source = new OuterNoWrappers();
120+
source.inner = new ArrayList<>();
121+
source.inner.add(new InnerNoWrappers("value"));
122+
123+
String xml = mapper.writerWithDefaultPrettyPrinter()
124+
.writeValueAsString(source);
125+
//System.err.println("XML:\n"+xml);
126+
OuterNoWrappers result = mapper.readValue(xml, OuterNoWrappers.class);
127+
assertNotNull(result.inner);
128+
assertEquals(1, result.inner.size());
129+
assertEquals("value",result.inner.get(0).str);
130+
}
131+
}
96132
}

0 commit comments

Comments
 (0)