ObjectMapper.readValue("123", Void.TYPE)
throws "should never occur"
#2679
Milestone
ObjectMapper.readValue("123", Void.TYPE)
throws "should never occur"
#2679
objectMapper.readValue("123", Void.class)
returns null.objectMapper.readValue("123", Void.TYPE)
throws JsonMappingException, with cause IllegalArgumentException, whose code comment reads "should never occur".objectMapper.readValue("123", void.class)
also throws, sincevoid.class == Void.TYPE
I would argue that Void.TYPE and void.class should also return null, unconditionally.
.. basically, in the same vein as if specifying Void.class, you get null, and considering
objectMapper.readValue("123", Integer.TYPE)
returns 123 - and that the only value a Void variable can have is null.Cause Exception:
The reason is that this NumberDeserializers first checks whether the class is primitive (yes), and then has checks for all of Integer.TYPE, Boolean.TYPE etc, but lacks one for Void.TYPE. It thus falls out of that "then" block, and hits the default "should never occur".
The reason why this hits me, is that I have a (de)serialization situation in my library where users must specify which type they need their incoming message as - but can also effectively say "I don't care". Up until now I've used Void.class for this, but have come to realize that this is actually not correct - as the Void class that holds the
TYPE
field is "just a random class". You want eithervoid.class
(lowercase 'v'), or "Void.TYPE" - these two are actually the same instance, as opposed toVoid.class
.The
Void.class
actually works because there is special handling for this case in JdkDeserializers:This does not catch the void.class (or Void.TYPE), and it is anyway too late, since the NumberDeserializers class already has crashed it.
Here's a small test:
Prints something like:
The text was updated successfully, but these errors were encountered: