Search code examples
javajacksonrestlet

JacksonConverter missing getObjectMapper() method


I'm using Restlet version 2.1.7 here is my Application class

public final class MyApplication extends Application {
  @Override
  public Restlet createInboundRoot() {
    Router router = (Router)super.createInboundRoot();
    .
    .
    .

    List<ConverterHelper> converters = Engine.getInstance().getRegisteredConverters();
    JacksonConverter jacksonConverter = (JacksonConverter)converters.get(2);
    SerializationConfig serializationConfig = jacksonConverter.getObjectMapper().getSerializationConfig();
    serializationConfig.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);

    return router;
  }
}

Now I am trying to upgrade to Restlet version 2.3.4 and I get compilation error for the next line:

        SerializationConfig serializationConfig = jacksonConverter.getObjectMapper().getSerializationConfig();

The compilation error is that JacksonConverter no longer has the method getObjectMapper()

How can I overcome this compilation error? I will be happy for Application and/or Response solutions.


Solution

  • The solution I used is to add JacksonConverter in the next manner:

            List<ConverterHelper> converters = Engine.getInstance().getRegisteredConverters();
            converters.add(new JacksonConverter());
    

    Also, in order to set SerializationInclusion as JsonSerialize.Inclusion.NON_NULL I used the annotation @JsonInclude(JsonInclude.Include.NON_NULL) for every response class I use in my resources.

    I could not find a more generic solution (in the application level), but this seems to work fine.