I am making a custom deserializer (extending StdDeserializer
) using the Jackson JSON library and I can't figure out what the purpose of the constructor parameters are. What is Class<?>
or JavaType valueType
used for by Jackson? Is it just because Java doesn't have reified generics and Jackson needs more information about the generic type you're making an instance of?
Jackson matches JSON structures with java classes. Just like JAXB maps java classes to XSD-s.
So, this Class<?>
(or JavaType) defines which java class belongs to this deserializer. These java classes can be anything that have the right annotations, like @JsonProperty
.
Another question: why is this class generic? This is so because [java.lang.Class][1]
is generic. If you want to do it correctly, then you specify it like this:
StdDeserializer serializer = new StdDeserializer(YourClass.class);
The point is that the StdSerializer
does not bound the classes you can specify.