According to masterSlave provided link and solution, i adopt it to Spring Boot. i face the problem at my Spring Boot project and solve it to create HibernateAwareObjectMapper
and define a custom new MappingJackson2HttpMessageConverter
like below.
First add dependecy for hibernate4 to pom.xml
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-hibernate4</artifactId>
<version>2.5.3</version>
</dependency>
Create HibernateAwareObjectMapper
class
/**
* https://github.com/FasterXML/jackson-datatype-hibernate
*
*/
public class HibernateAwareObjectMapper extends ObjectMapper {
/**
*
*/
private static final long serialVersionUID = 1L;
public HibernateAwareObjectMapper() {
registerModule(new Hibernate4Module());
}
}
Add custom MappingJackson2HttpMessageConverter
class to Application.java
@Bean
public MappingJackson2HttpMessageConverter customJackson2HttpMessageConverter() {
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
HibernateAwareObjectMapper hibernateAwareObjectMapper = new HibernateAwareObjectMapper();
jsonConverter.setObjectMapper(hibernateAwareObjectMapper);
return jsonConverter;
}
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(customJackson2HttpMessageConverter());
super.addDefaultHttpMessageConverters(converters);
}