No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyIn

No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: ***************_$$_javassist_15["hibernateLazyInitializer"])
......


环境Maven+Tomcat/Glassfish


我在用Glassfish部署的时候不会报错,直接用pom.xml build时运行到要使用ObjectMapper时
会报该错

这个已经提示得比较清楚了就是懒加载和循环引用造成Jckson没法用
提示使用hibernateLazyInitializer

在class前面加上@JsonIgnoreProperties(value={"hibernateLazyInitializer"})这个就对了吗

答案是否定的,至少我这里行不通
完整的应该是这样
@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"})

一切OK

如果在字段前面加上@JsonIgnore,则查找出来的json对象中会把相关字段全部为null值

猜你喜欢

转载自redsky008.iteye.com/blog/1345279
今日推荐