Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure Jackson to omit lazy-loading attributes in Spring Boot

In spring boot mvc project with pure java configuration how to configure Jackson to omit lazy load Attributes

like image 811
R K Punjal Avatar asked Nov 16 '15 00:11

R K Punjal


1 Answers

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();
}
like image 196
Robert Hunt Avatar answered Sep 19 '22 15:09

Robert Hunt