Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Jackson gets to know when to use BeanSerializer and MapSerializer

I am having a bean, where Map is being returned in response, and this bean is invoked via REST interface using RESTEasy.

The jackson library is using BeanSerializer(internally) rather than using MapSerializer while sending the response back.

so is there any annotation being used here for letting it know which serializer to use for the bean.

Thanks in advance.

like image 693
Vishant Mehta Avatar asked Nov 04 '25 16:11

Vishant Mehta


1 Answers

Jackson BeanSerializer extends BeanSerializerBase that will serialize fields based on their types (defined by TypeSerializer) using JsonSerializer defined by SerializerProvider. And the SerializerProvider will use the MapSerializer for everything that will extends java.util.map.

So ... the jackson library use the MapSerializer to serialize maps ...

Anyway, you can use the @JsonSerialize annotation to manage how jackson will serialize the proprty, more info in the documentation : https://github.com/FasterXML/jackson-databind/wiki/Databind-Annotations

Regards,

Loïc

like image 106
loicmathieu Avatar answered Nov 07 '25 11:11

loicmathieu



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!