Skip to content

Optimize use of Jackson ObjectMapper instances #1789

@john-f-xoom

Description

@john-f-xoom

I wanted to customize JSON serialization of objects returned by the overridden invoke() method of a class extending AbstractEndpoint. Judging by http://docs.spring.io/spring-boot/docs/current/reference/html/howto-spring-mvc.html#howto-customize-the-jackson-objectmapper, I thought I could control serialization of those objects by providing a corresponding Jackson Module as a bean, but the EndpointMBean class creates its own ObjectMapper instance rather than obtaining it from the Spring context. This puts it out of reach from installing custom serializers, and also contravenes the advice at http://wiki.fasterxml.com/JacksonBestPracticesPerformance about re-using object mappers to avoid the expense of creating them.

There seem to be other places that create their own ObjectMapper instances as well, sometimes on each transaction. Two examples are org.springframework.boot.json.JacksonJsonParser and org.springframework.boot.actuate.endpoint.ConfigurationPropertiesReportEndpoint.

Why don't EndpointMBean, JacksonJsonParser and ConfigurationPropertiesReportEndpoint use the shared object mapper instance instead of creating their own instances? If it would be okay for them to do so, I would be willing to submit that change as a patch.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions