Configure Jackson to omit lazy-loading attributes in Spring Boot

With recent versions of Spring Boot this is much easier.

Any beans of type com.fasterxml.jackson.databind.Module will be automatically registered with the auto-configured Jackson2ObjectMapperBuilder and applied to any ObjectMapper instances that it creates. This provides a global mechanism for contributing custom modules when you add new features to your application.

74.3 Customize the Jackson ObjectMapper

First ensure you have the required Jackson dependency:

<dependency>
    <groupId>com.fasterxml.jackson.datatype</groupId>
    <artifactId>jackson-datatype-hibernate4</artifactId>
</dependency>

You can then just include the module as a @Bean in the application context.

@Bean
public Module hibernate4Module()
{
    return new Hibernate4Module();
}

Leave a Comment