Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Class<?> vc or JavaType valueType used for in the constructor of Jackson's StdDeserializer

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?

like image 526
zjuhasz Avatar asked Oct 27 '25 10:10

zjuhasz


1 Answers

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.

like image 145
Tamas Rev Avatar answered Oct 29 '25 00:10

Tamas Rev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!