Using Spring Boot 1.2.2 to create an Spring MVC application. I am also using Spring HATEOAS.
The issue I am having is that my configured ObjectMapper is used properly when my controller methods return a List<>, but a different ObjectMapper is being used when I return my Resource classes (e.g. MyClass extends ResourceSupport)
It's a more than a little frustrating to try to configure Jackson's ObjectMapper. I have followed the documentation and added my own ObjectMapper @Bean to a @Configuration class and annotated it with @Primary, and that one is being used when serializing List<>.
Setting a breakpoint in the ObjectMapper constructor breakpoint reveals that the constructor is called about 20 times. I made a poor summary of each scenario:
@Bean annotated with @Primary)I'd recommend either using application.properties to configure Jackson or, if you need more control, declaring your own Jackson2ObjectMapperBuilder bean. In either case, you end up with a Jackson2ObjectMapperBuilder bean in the application context that can then be used by other components to create ObjectMappers with your desired configuration or to apply that configuration to any existing ObjectMappers.
Edit: there's an issue open to improve Actuator's ObjectMapper usage.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With