0

I have inherited some legacy code that uses Jackson 1.9.2 and am wanting to upgrade it to Jackson 2.x. One point of contention is the following:

class CustomObjectMapper extends ObjectMapper {
    CustomObjectMapper(KeySerializer keySerializer) {
        // StdSerializerProvider doesn't exist in Jackson 2.x
        final StdSerializerProvider sp = new StdSerializerProvider();
        sp.setNullValueSerializer(new NullSerializer());
        sp.setDefaultKeySerializer(keySerializer);
        setSerializerProvider(sp);
    }
}

The trouble I am having is that StdSerializerProvider exists in Jackson 1.9.x, but not in Jackson 2.x. Is there an equivalent class for this that will preserve the existing behavior? Or is a replacement necessary at all?

Thunderforge
  • 19,637
  • 18
  • 83
  • 130

1 Answers1

3

The DefaultSerializerProvider must be what you're looking for. Note that they both this and the StdSerializerProvider of Jackson 1.x are subclasses of SerializerProvider. They also have very similar methods.

Note that StdSerializerProvider is a concrete class while DefaultSerializerProvider is abstract. However, you can create a new DefaultSerializerProvider.Impl to create a concrete class.

Thunderforge
  • 19,637
  • 18
  • 83
  • 130
Costi Ciudatu
  • 37,042
  • 7
  • 56
  • 92
  • Both this and `StdSerializerProvider` implement the interface `SerializerProvider`, so I believe that this is what I am looking for. I did notice that the class is abstract, but you can use `new DefaultSerializerProvider.Impl()` to get a concrete class. – Thunderforge Sep 07 '16 at 17:05