本文链接:https://blog.csdn.net/qq_42136250/article/details/88581844
@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"})
解决方案二: 重写:ObjectMapper,然后在applicationContext-mvc.xml 配置这个映射(这个方法一劳永逸,之后在Spring集成JPA进行懒加载的时候,都会避免No serializer的错误)
package cn.jiedada.aisell.common; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; public class JsonMapper extends ObjectMapper { public JsonMapper() { this.setSerializationInclusion(JsonInclude.Include.NON_NULL); // 设置 SerializationFeature.FAIL_ON_EMPTY_BEANS 为 false this.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); } }
在applicationContext-mvc.xml 配置
<mvc:annotation-driven> <mvc:message-converters> <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>application/json; charset=UTF-8</value> <value>application/x-www-form-urlencoded; charset=UTF-8</value> </list> </property> <!-- No serializer:配置 objectMapper 为我们自定义扩展后的 CustomMapper,解决了返回对象有关系对象的报错问题 --> <property name="objectMapper"> <bean class="cn.jiedada.aisell.common.JsonMapper"></bean> </property> </bean> </mvc:message-converters> </mvc:annotation-driven>
原文:https://www.cnblogs.com/xiaoruirui/p/11669569.html