在具有纯Java配置的Spring Boot MVC项目中,如何配置Jackson省略延迟加载属性
我使用springboot和hibernamte5.0.x。有用!
1. pom.xml
<dependency> <groupId>com.fasterxml.jackson.datatype</groupId> <artifactId>jackson-datatype-hibernate5</artifactId> <version>2.8.4</version> </dependency>
2. Webconfig
@Configuration public class WebConfig implements WebMvcConfigurer { public void extendMessageConverters(List<HttpMessageConverter<?>> converters) { for (HttpMessageConverter converter : converters) { if (converter instanceof org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) { ObjectMapper mapper = ((MappingJackson2HttpMessageConverter) converter).getObjectMapper(); mapper.registerModule(new Hibernate5Module()); // replace Hibernate4Module() with the proper class for your hibernate version. } } } }