1

I am using JACKSON 1.6.3 version. I have one class which has a reference to itself and JACKSON serializer is failing with complains about "circular references". I would like to disable serialization of this class. This is a third party class and I can not add any annotation to it, I am wondering if there is a way to disable this type of object being serialized. I am ok if the serializer ignores the entire object.

Shamik
  • 6,938
  • 11
  • 55
  • 72

2 Answers2

3

I fixed the issue by creating a custom JsonSerializer<T> for the type and registered it with ObjectMapper

mapper = new ObjectMapper();
CustomSerializerFactory factory = new CustomSerializerFactory();
factory.addSpecificMapping(<Type to be handled>, <Custom Serializer>);
mapper.setSerializerFactory(factory);
Shamik
  • 6,938
  • 11
  • 55
  • 72
0

This can also be done using JacksonMixInAnnotations.

See the accepted answer on How can I tell jackson to ignore a property for which I don't have control over the source code?

Mahmoud
  • 9,729
  • 1
  • 36
  • 47