Used version: jackson 2.13.0
In general writing and reading of Double.NaN works fine. However, if I want to write a class like this
public class SimpleClass
{
private Map<String, Double> map;}
and the map contains a Double.NaN value, it gets tricky.
With
ObjectMapper.DefaultTyping.NON_FINAL)
it works, with
ObjectMapper.DefaultTyping.EVERYTHING)
a json is written, which cannot be read. Reading fails with an Exception
Exception in thread "main" com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `java.lang.Double` from Array value (token `JsonToken.START_ARRAY`)
at [Source: (String)"[ "de.epoq.rs.sai.utils.JacksonNaNMapValueExample$SimpleClass", {
"map" : [ "java.util.HashMap", {
"A" : 1.0,
"B" : [ "java.lang.Double", "NaN" ],
"C" : [ "java.lang.Double", "Infinity" ]
} ]
} ]"; line: 4, column: 11] (through reference chain: de.epoq.rs.sai.utils.JacksonNaNMapValueExample$SimpleClass["map"]->java.util.HashMap["B"])
at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59)
at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1741)
Please see the attached file for a full working example.
My question is:
Why is this happening ? Why is the map within the class is treated differently now ?