|
3 | 3 | import java.util.*;
|
4 | 4 |
|
5 | 5 | import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
| 6 | +import com.fasterxml.jackson.dataformat.xml.JacksonXmlAnnotationIntrospector; |
6 | 7 | import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
7 | 8 | import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
|
8 | 9 | import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
|
@@ -51,7 +52,7 @@ protected InnerBean2() { }
|
51 | 52 | public InnerBean2(String s) { str2 = s; }
|
52 | 53 | }
|
53 | 54 |
|
54 |
| - public void testIssue469() throws Exception |
| 55 | + public void testIssue469WithDefaults() throws Exception |
55 | 56 | {
|
56 | 57 | // Here we just use default settings (which defaults to wrappers)
|
57 | 58 | final XmlMapper mapper = newMapper();
|
@@ -93,4 +94,39 @@ public void testIssue469() throws Exception
|
93 | 94 | assertEquals(1, mid.inner2.size());
|
94 | 95 | assertEquals("aaaa", mid.inner2.get(0).str2);
|
95 | 96 | }
|
| 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 | + } |
96 | 132 | }
|
0 commit comments