We use this in Play 2.3.x
@Override
public void onStart(Application app) {
// Setup the ObjectMapper to support JodaTime (Un)marshalling
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JodaModule());
Json.setObjectMapper(mapper);
}
Would the best practice for doing this in Play 2.4.x using DI. Would it be to create a new Class to perform this in the Constructor and then configure DI?
@Singleton
public class CustomJsonMapper {
protected CustomJsonMapper() {
// Setup the ObjectMapper to support JodaTime (Un)marshalling
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JodaModule());
Json.setObjectMapper(mapper);
}
}
public class CommonModule extends AbstractModule {
protected void configure() {
bind(CustomJsonMapper.class).asEagerSingleton();
}
}
application.conf -> play.modules.enabled += "common.CommonModule"