0

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?

Laures
  • 5,389
  • 11
  • 50
  • 76
  • Can you elaborate bit more what specifically you are trying to do? – StaxMan Feb 07 '14 at 04:09
  • my serializer `FubarSerializer` handles all `Fubar` instances. it can serialize these instances in two ways (A and B). i have a bunch of those Serializers wrapped into a module. i want to configure if they use A or B globaly with a setter on the module. – Laures Feb 07 '14 at 11:03

1 Answers1

0

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.

StaxMan
  • 113,358
  • 34
  • 211
  • 239