@@ -68,9 +68,15 @@ public void testSimpleNested() throws Exception
6868 public void testDuplicatedElementsSwallowing () throws Exception
6969 {
7070 // 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+
7378 }
79+
7480
7581 /**
7682 * Unit test that verifies that we can write sample document from JSON
@@ -286,8 +292,10 @@ private String _readXmlWriteJson(String xml) throws IOException
286292 return w .toString ();
287293 }
288294
289- private String _readXmlToMapToJson (String xml ) throws IOException
295+ private String _readXmlToMapToJson (String xml , boolean state ) throws IOException
290296 {
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 ));
292300 }
293301}
0 commit comments