1
votes

I know how to configure the Jackson ObjectMapper in Spring Boot through application properties as per https://docs.spring.io/spring-boot/docs/current/reference/html/howto-spring-mvc.html#howto-customize-the-jackson-objectmapper.

How do I control the Jackson JsonFactory.Features that way?

In Spring 4.3.14 Jackson2ObjectMapperBuilder instantiates ObjectMapper through its default constructor i.e. without passing a JsonFactory. This behavior was obviously changed/fixed later: https://github.com/spring-projects/spring-framework/blob/master/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java#L621

1

1 Answers

1
votes
@Bean
public ObjectMapper tolerantObjectMapper() {
    log.info("Creating Object mapper");
    final JsonFactory jsonFactory = new JsonFactory();
    jsonFactory.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES);
    ObjectMapper objectMapper = new ObjectMapper(jsonFactory);
    return objectMapper;
}