|
| 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