Can't set ProblemHandler to ObjectMapper in Spring Boot

It's not possible to directly add a DeserializationProblemHandler to the ObjectMapper via a Jackson2ObjectMapperBuilder or Jackson2ObjectMapperBuilderCustomizer. Calling build() on the builder is a no-go, since the resulting ObjectMapper is local to the method: Spring itself will call build() later, creating another ObjectMapper instance.

However, it's possible to do so by registering a Jackson module :

  • the builder has a modules() method
  • the module has access via setupModule() to a SetupContext instance, which has a addDeserializationProblemHandler() method

This should then work

public Jackson2ObjectMapperBuilderCustomizer customizer() {
    return new Jackson2ObjectMapperBuilderCustomizer() {
        public void customize(Jackson2ObjectMapperBuilder builder) {
            builder.modules(new MyModule());

private static class MyModule extends SimpleModule {
    public void setupModule(SetupContext context) {
        // Required, as documented in the Javadoc of SimpleModule
        context.addDeserializationProblemHandler(new MyDeserializationProblemHandler());

private static class MyDeserializationProblemHandler extends DeserializationProblemHandler {
    public boolean handleUnknownProperty(DeserializationContext ctxt,
                                         JsonParser p,
                                         JsonDeserializer<?> deserializer,
                                         Object beanOrClass,
                                         String propertyName)
            throws IOException {
        return super.handleUnknownProperty(ctxt, p, deserializer, beanOrClass, propertyName);