Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make fasterxml ObjectMapper work with codehaus annotations

Tags:

java

json

jackson

I'm using the ObjectMapper class from the fasterxml package (com.fasterxml.jackson.databind.ObjectMapper) to serialize some POJOs.

The problem I'm facing is that all the annotations in the POJOs are from the older codehaus library. The fasterxml ObjectMapper is not recognizing the codehaus jackson annotations.
One possible solution is to update the annotations in the POJO to fasterxml, but the POJOs are provided by a third party, hence I cannot modify it.

How can I solve this problem?

like image 213
Raj Avatar asked Jul 01 '26 21:07

Raj


1 Answers

You can provide your own AnnotationIntrospector to process old annotation.

ObjectMapper mapper = new ObjectMapper();
mapper.setAnnotationIntrospector(new MyAnnotationIntrospector());

You can also checkout the jackson-legacy-introspector listed on the jackson github. It's an existing implementation of AnnotationIntrospector for old annotations.

like image 73
JEY Avatar answered Jul 04 '26 01:07

JEY



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!