I tried to add custom problem handler to object mapper with Jackson2ObjectMapperBuilderCustomizer:
@Bean
public Jackson2ObjectMapperBuilderCustomizer customizer() {
return new Jackson2ObjectMapperBuilderCustomizer() {
@Override
public void customize(Jackson2ObjectMapperBuilder builder) {
ObjectMapper m = builder.build();
m.addHandler(
new DeserializationProblemHandler() {
@Override
public boolean handleUnknownProperty(DeserializationContext ctxt, JsonParser p, JsonDeserializer<?> deserializer, Object beanOrClass, String propertyName) throws IOException {
System.out.println("ahahahaa");
return super.handleUnknownProperty(ctxt, p, deserializer, beanOrClass, propertyName);
}
}
);
}
};
}
But when i autowired ObjectMapper bean _problemHandlers property is null.
I also tried just customize existed ObjectMapper with:
@Autowired
public customize(ObjectMapper mapper) {
...
}
But result is the same. I don't know who can erasure this property. I don't initialize another builders/factories/etc of object mapper in another place at all. What i'm doing wrong?
handleUnknownProperty
when my request has an invalid JSON field. Am I missing something here ? – Freethinker