Skip to content

Commit ea65c36

Browse files
committed
Fix #205 (actually, add unit test; fix itself from databind/2733)
1 parent 2d522a6 commit ea65c36

File tree

3 files changed

+70
-20
lines changed

3 files changed

+70
-20
lines changed

release-notes/VERSION-2.x

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ Project: jackson-dataformat-xml
66

77
2.12.0 (not yet released)
88

9+
#205: `XmlMapper`/`UntypedObjectDeserializer` swallows duplicated elements in
10+
XML documents
11+
(reported by joaovarandas@github)
912
#262: Make `ToXmlGenerator` non-final
1013
(requested by Dave J)
1114
#273: Input mismatch with case-insensitive properties
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.fasterxml.jackson.dataformat.xml.deser;
2+
3+
import com.fasterxml.jackson.databind.JsonNode;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import com.fasterxml.jackson.databind.ObjectWriter;
6+
import com.fasterxml.jackson.databind.json.JsonMapper;
7+
import com.fasterxml.jackson.databind.node.ArrayNode;
8+
import com.fasterxml.jackson.databind.node.ObjectNode;
9+
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
10+
11+
// for [dataformat-xml#205], handling "untyped" ({@code java.lang.Object}-targeted)
12+
// deserialization, including handling of element sequences
13+
public class UntypedObjectDeser205Test extends XmlTestBase
14+
{
15+
private final ObjectMapper XML_MAPPER = newMapper();
16+
17+
private final ObjectMapper JSON_MAPPER = new JsonMapper();
18+
19+
public void testRepeatingElements() throws Exception
20+
{
21+
final String XML =
22+
"<person>\n" +
23+
" <name>John</name>\n" +
24+
" <parent>Jose</parent>\n" +
25+
" <parent>Maria</parent>\n" +
26+
" <dogs>\n" +
27+
" <count>3</count>\n" +
28+
" <dog>\n" +
29+
" <name>Spike</name>\n" +
30+
" <age>12</age>\n" +
31+
" </dog>\n" +
32+
" <dog>\n" +
33+
" <name>Brutus</name>\n" +
34+
" <age>9</age>\n" +
35+
" </dog>\n" +
36+
" <dog>\n" +
37+
" <name>Bob</name>\n" +
38+
" <age>14</age>\n" +
39+
" </dog>\n" +
40+
" </dogs>\n" +
41+
"</person>";
42+
final JsonNode fromXml = JSON_MAPPER.valueToTree(XML_MAPPER.readValue(XML, Object.class));
43+
final ObjectNode exp = JSON_MAPPER.createObjectNode();
44+
exp.put("name", "John");
45+
{
46+
exp.putArray("parent")
47+
.add("Jose")
48+
.add("Maria");
49+
ArrayNode dogs = exp.putObject("dogs")
50+
.put("count", "3")
51+
.putArray("dog");
52+
dogs.addObject()
53+
.put("name", "Spike")
54+
.put("age", "12");
55+
dogs.addObject()
56+
.put("name", "Brutus")
57+
.put("age", "9");
58+
dogs.addObject()
59+
.put("name", "Bob")
60+
.put("age", "14");
61+
}
62+
if (!fromXml.equals(exp)) {
63+
ObjectWriter w = JSON_MAPPER.writerWithDefaultPrettyPrinter();
64+
fail("Expected:\n"+w.writeValueAsString(exp)+"\ngot:\n"+w.writeValueAsString(fromXml));
65+
}
66+
}
67+
}

src/test/java/com/fasterxml/jackson/dataformat/xml/misc/NodeTest.java

-20
This file was deleted.

0 commit comments

Comments
 (0)