Skip to content

Commit e7300de

Browse files
committed
Add actual failing test for #469
1 parent 3951a95 commit e7300de

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package com.fasterxml.jackson.dataformat.xml.failing;
2+
3+
import java.util.*;
4+
5+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
6+
7+
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
8+
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
9+
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
10+
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
11+
12+
// Actual reproduction of [dataformat-xml#469]: quite specific set up
13+
// needed, alas
14+
public class ListDeser469FailingTest extends XmlTestBase
15+
{
16+
static class OuterBean {
17+
public MiddleBean middle;
18+
}
19+
20+
@JsonPropertyOrder({"inner1", "inner2"})
21+
static class MiddleBean
22+
{
23+
public InnerBean1 inner1;
24+
25+
@JacksonXmlElementWrapper(useWrapping = false)
26+
public List<InnerBean2> inner2;
27+
}
28+
29+
static class InnerBean1
30+
{
31+
public String str;
32+
33+
// Fail if (and only if!) wrapping disabled, by default or via
34+
// annotations
35+
// (that is; if this is commented out, passes)
36+
@JacksonXmlElementWrapper(useWrapping = false)
37+
public List<InnerBean1Item> item;
38+
}
39+
40+
static class InnerBean1Item
41+
{
42+
@JacksonXmlProperty(isAttribute = true)
43+
public String id;
44+
}
45+
46+
static class InnerBean2
47+
{
48+
@JacksonXmlProperty(isAttribute = true)
49+
public String str2;
50+
51+
protected InnerBean2() { }
52+
public InnerBean2(String s) { str2 = s; }
53+
}
54+
55+
/*
56+
/**********************************************************************
57+
/* Test methods
58+
/**********************************************************************
59+
*/
60+
61+
public void testIssue469WithDefaults() throws Exception
62+
{
63+
// Here we just use default settings (which defaults to using wrappers)
64+
final XmlMapper mapper = newMapper();
65+
66+
// First: create POJO value to test round-trip:
67+
{
68+
OuterBean source = new OuterBean();
69+
source.middle = new MiddleBean();
70+
List<InnerBean2> items = new ArrayList<>();
71+
items.add(new InnerBean2("foo"));
72+
source.middle.inner2 = items;
73+
74+
String xml = mapper.writerWithDefaultPrettyPrinter()
75+
.writeValueAsString(source);
76+
77+
OuterBean result = mapper.readValue(xml, OuterBean.class);
78+
79+
MiddleBean mid = result.middle;
80+
assertNotNull(mid);
81+
assertNotNull(mid.inner2);
82+
assertEquals(1, mid.inner2.size());
83+
assertEquals("foo", mid.inner2.get(0).str2);
84+
}
85+
86+
// And then verify from XML String
87+
String xmlInput = "<OuterBean>\n" +
88+
" <middle>\n" +
89+
" <inner1/>\n" +
90+
" <inner2 str2='aaaa'/>\n" +
91+
" </middle>\n" +
92+
"</OuterBean>\n";
93+
94+
OuterBean outer = mapper.readValue(xmlInput, OuterBean.class);
95+
96+
MiddleBean mid = outer.middle;
97+
assertNotNull(mid);
98+
99+
assertNotNull(mid.inner2);
100+
assertEquals(1, mid.inner2.size());
101+
assertEquals("aaaa", mid.inner2.get(0).str2);
102+
}
103+
}

0 commit comments

Comments
 (0)