@@ -68,9 +68,15 @@ public void testSimpleNested() throws Exception
68
68
public void testDuplicatedElementsSwallowing () throws Exception
69
69
{
70
70
// 04-Aug-2016, jpvarandas: ensure that duplicated elements get wrapped into an array and do not get swallowed (deser and ser)
71
- assertEquals ("{\" name\" :\" John\" ,\" parent\" :[\" Jose\" ,\" Maria\" ],\" dogs\" :{\" count\" :\" 3\" ,\" dog\" :[{\" name\" :\" Spike\" ,\" age\" :\" 12\" },{\" name\" :\" Brutus\" ,\" age\" :\" 9\" },{\" name\" :\" Bob\" ,\" age\" :\" 14\" }]}}" ,
72
- _readXmlToMapToJson ("<person><name>John</name><parent>Jose</parent><parent>Maria</parent><dogs><count>3</count><dog><name>Spike</name><age>12</age></dog><dog><name>Brutus</name><age>9</age></dog><dog><name>Bob</name><age>14</age></dog></dogs></person>" ));
71
+ assertEquals ("{\" id\" :\" 10\" ,\" name\" :\" John\" ,\" parent\" :[\" Jose\" ,\" Maria\" ],\" dogs\" :{\" count\" :\" 3\" ,\" dog\" :[{\" name\" :\" Spike\" ,\" age\" :\" 12\" },{\" name\" :\" Brutus\" ,\" age\" :\" 9\" },{\" name\" :\" Bob\" ,\" age\" :\" 14\" }]},\" addresses\" :{\" address\" :[\" Brazil\" ,\" US\" ]}}" ,
72
+ _readXmlToMapToJson ("<person id=\" 10\" ><name>John</name><parent>Jose</parent><parent>Maria</parent><dogs><count>3</count><dog><name>Spike</name><age>12</age></dog><dog><name>Brutus</name><age>9</age></dog><dog><name>Bob</name><age>14</age></dog></dogs><addresses><address>Brazil</address><address>US</address></addresses></person>" , true ));
73
+
74
+ // using 'false' should keep the deser the way it was before ...
75
+ assertEquals ("{\" id\" :\" 10\" ,\" name\" :\" John\" ,\" parent\" :\" Maria\" ,\" dogs\" :{\" count\" :\" 3\" ,\" dog\" :{\" name\" :\" Bob\" ,\" age\" :\" 14\" }},\" addresses\" :{\" address\" :\" US\" }}" ,
76
+ _readXmlToMapToJson ("<person id=\" 10\" ><name>John</name><parent>Jose</parent><parent>Maria</parent><dogs><count>3</count><dog><name>Spike</name><age>12</age></dog><dog><name>Brutus</name><age>9</age></dog><dog><name>Bob</name><age>14</age></dog></dogs><addresses><address>Brazil</address><address>US</address></addresses></person>" , false ));
77
+
73
78
}
79
+
74
80
75
81
/**
76
82
* Unit test that verifies that we can write sample document from JSON
@@ -286,8 +292,10 @@ private String _readXmlWriteJson(String xml) throws IOException
286
292
return w .toString ();
287
293
}
288
294
289
- private String _readXmlToMapToJson (String xml ) throws IOException
295
+ private String _readXmlToMapToJson (String xml , boolean state ) throws IOException
290
296
{
291
- return _objectWriter .writeValueAsString (_xmlMapper .readValue (xml , Object .class ));
297
+ XmlMapper _xmlMapperWithOption = new XmlMapper ().setUseXmlUntypedObjectDeserModule (state );
298
+
299
+ return _objectWriter .writeValueAsString (_xmlMapperWithOption .readValue (xml , Object .class ));
292
300
}
293
301
}
0 commit comments