XmlMapper does not support multi-dimensional arrays (original) (raw)
Serializing multidimensional arrays to XML looses dimension information
When serializing an two dimensional array to XML, one dimension gets lost. In other words, serializing an two dimensional array to XML produces the same result as serializing an one dimensional array. When serializing to JSON, the information is NOT lost.
Version information
2.14 (jackson-dataformat-xml-2.14.0.jar)
To Reproduce
public static void main(String[] args) throws JsonProcessingException {
final ObjectMapper xmlMapper = new XmlMapper();
final ObjectMapper mapper = new ObjectMapper();
boolean[] booleanArray = new boolean[] {
true, false
};
boolean[][] boolean2DArray = new boolean[][] {
{
true
}, {
false
}
};
serialize(xmlMapper, booleanArray, "1DArray to XML");
serialize(xmlMapper, boolean2DArray, "2DArray to XML");
serialize(mapper, booleanArray, "1DArray to JSON");
serialize(mapper, boolean2DArray, "2DArray to JSON");
}
private static void serialize(ObjectMapper mapper, Object object, String text) throws JsonProcessingException {
String singleArrayResult = mapper.writeValueAsString(object);
System.out.println(text + ": " + singleArrayResult);
}
will print
1DArray to XML: <booleans><item>true</item><item>false</item></booleans>
2DArray to XML: <booleans><item>true</item><item>false</item></booleans>
1DArray to JSON: [true,false]
2DArray to JSON: [[true],[false]]