How can i influence instance creation for annotated serializers

103 views Asked by At

I wrote a jackson module to enable a specific type of serialization. Now i want to enable global configuration of one of the new serializers. so i have to set a property on a serializer instance during creation.

Is there a way i can do that from within a jackson module?

1

There are 1 answers

0
StaxMan On

Module interface is stateless, one-of-thing, so it does not have default wiring to affect things it adds.

But what you can do is to use a work-around; possibilities include:

  • use of ThreadLocal; set before serialization, read from serializer
  • use new (Jackson 2.3) feature of "attributes"; can set those for writing (ObjectWriter.setAttribute()) and reading (ObjectReader.setAttribute()), accessible by serializer/deserializer through context object (SerializerProvider / DeserializationContext)

So hopefully one of these works for your use case.