Skip to content

Commit 8a8c2e5

Browse files
committed
Add a failing test for #498
1 parent d6655fd commit 8a8c2e5

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

src/test/java/com/fasterxml/jackson/dataformat/xml/deser/MapDeserializationTest.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.fasterxml.jackson.dataformat.xml.deser;
22

3+
import java.util.Collections;
4+
import java.util.LinkedHashMap;
35
import java.util.Map;
46

57
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
@@ -13,13 +15,13 @@ public class MapDeserializationTest extends XmlTestBase
1315
/**********************************************************
1416
*/
1517

16-
private final XmlMapper MAPPER = newMapper();
18+
private final XmlMapper XML_MAPPER = newMapper();
1719

1820
// [dataformat-xml#14]
1921
public void testMapWithAttr() throws Exception
2022
{
2123
final String xml = "<order><person lang='en'>John Smith</person></order>";
22-
Map<?,?> map = MAPPER.readValue(xml, Map.class);
24+
Map<?,?> map = XML_MAPPER.readValue(xml, Map.class);
2325

2426
// Will result in equivalent of:
2527
// { "person" : {
@@ -32,6 +34,10 @@ public void testMapWithAttr() throws Exception
3234
// we would just have '{ "person" : "John Smith" }'
3335

3436
assertNotNull(map);
37+
assertEquals(1, map.size());
38+
Map<String,Object> inner = new LinkedHashMap<>();
39+
inner.put("lang", "en");
40+
inner.put("", "John Smith");
41+
assertEquals(Collections.singletonMap("person", inner), map);
3542
}
36-
3743
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.fasterxml.jackson.dataformat.xml.failing;
2+
3+
import java.util.Map;
4+
5+
import com.fasterxml.jackson.databind.ObjectMapper;
6+
import com.fasterxml.jackson.databind.json.JsonMapper;
7+
8+
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
9+
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
10+
11+
public class MapDeserialization498Test extends XmlTestBase
12+
{
13+
/*
14+
/**********************************************************************
15+
/* Test methods
16+
/**********************************************************************
17+
*/
18+
19+
private final XmlMapper XML_MAPPER = newMapper();
20+
21+
private final ObjectMapper JSON_MAPPER = new JsonMapper();
22+
23+
// [dataformat-xml#498]
24+
public void testRootLevelMap() throws Exception
25+
{
26+
final String xml = "<result>\n"
27+
+ " <hello>world</hello>\n"
28+
+ " <lists>1</lists>\n"
29+
+ " <lists>2</lists>\n"
30+
+ " <lists></lists>\n"
31+
+ " <lists>\n"
32+
+ " <inner>internal</inner>\n"
33+
+ " <time>123</time>\n"
34+
+ " </lists>\n"
35+
+ " <lists>3</lists>\n"
36+
+ " <lists>test</lists>\n"
37+
+ " <lists></lists>\n"
38+
+ " <single>one</single>\n"
39+
+ "</result>";
40+
41+
Map<?,?> expMap = JSON_MAPPER.readValue(a2q(
42+
"{'hello':'world','lists':['1','2','',"
43+
+"{'inner':'internal','time':'123'},'3','test',''],'single':'one'}"),
44+
Map.class);
45+
46+
Map<?,?> map = XML_MAPPER.readValue(xml, Map.class);
47+
48+
// Work around: nominal target type of Object
49+
// Map<?,?> map = (Map<?,?> ) XML_MAPPER.readValue(xml, Object.class);
50+
51+
assertEquals(expMap, map);
52+
}
53+
}

0 commit comments

Comments
 (0)