Skip to content

Commit 3069602

Browse files
committed
Add a unit test for #101
1 parent 5fc1112 commit 3069602

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

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

+53-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.*;
44

5+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
56
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
67
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
78
import com.fasterxml.jackson.dataformat.xml.annotation.*;
@@ -27,6 +28,32 @@ static class Optionals {
2728
public List<Optional> optional;
2829
}
2930

31+
// For [Issue#101]
32+
@JacksonXmlRootElement(localName = "root")
33+
@JsonPropertyOrder({ "unwrapped", "name" })
34+
static class Root {
35+
@JacksonXmlProperty(localName = "unwrapped")
36+
@JacksonXmlElementWrapper(useWrapping = false)
37+
public List<UnwrappedElement> unwrapped;
38+
39+
public String name;
40+
}
41+
42+
static class UnwrappedElement {
43+
public UnwrappedElement () {}
44+
45+
public UnwrappedElement (String id, String type) {
46+
this.id = id;
47+
this.type = type;
48+
}
49+
50+
@JacksonXmlProperty(isAttribute = true)
51+
public String id;
52+
53+
@JacksonXmlProperty(isAttribute = true)
54+
public String type;
55+
}
56+
3057
/*
3158
/**********************************************************
3259
/* Unit tests
@@ -51,4 +78,29 @@ public void testOptionalsWithMissingType() throws Exception
5178
assertEquals("123-456-7890", opt.number);
5279
assertEquals("NOT SET", opt.type);
5380
}
54-
}
81+
82+
// [Issue#101]
83+
public void testWithTwoAttributes() throws Exception
84+
{
85+
final String EXP = "<root>"
86+
+"<unwrapped id=\"1\" type=\"string\"/>"
87+
+"<unwrapped id=\"2\" type=\"string\"/>"
88+
+"<name>test</name>"
89+
+"</root>";
90+
Root rootOb = new Root();
91+
rootOb.unwrapped = Arrays.asList(
92+
new UnwrappedElement("1", "string"),
93+
new UnwrappedElement("2", "string")
94+
);
95+
rootOb.name = "test";
96+
97+
// First, serialize, which works
98+
String xml = MAPPER.writeValueAsString(rootOb);
99+
assertEquals(EXP, xml);
100+
101+
// then try deserialize
102+
Root result = MAPPER.readValue(xml, Root.class);
103+
assertNotNull(result);
104+
assertEquals(rootOb.name, result.name);
105+
}
106+
}

0 commit comments

Comments
 (0)