I’m experiencing a strange Jackson issue. The XmlMapper could not deserialize what is serialized by itself. And the error only occurs when there’re nulls in the Double array. A sample test case to reproduce the issue is below:
@Test
public void testDerSer(){
Double[] testDouble = new Double[]{null, null, null, 3.0d, 34.5d};
try {
ObjectMapper xmlMapper = new XmlMapper();
byte[] bytes = xmlMapper.writeValueAsBytes(testDouble);
System.out.println(new String(bytes));
Double[] doubles = xmlMapper.readValue(bytes, Double[].class);
System.out.println(doubles);
}
catch (IOException e) {
e.printStackTrace();
}
}
The serialized payload looks like this:
<Doubles><item/><item/><item/><item>3.0</item><item>34.5</item></Doubles>
And the error is:
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.Double` out of START_OBJECT token
If you replace
Double[]
withArrayList
you get resultthen you get