spring mvc 解决json 死循环序列化问题

问题记录:

前端说后台抛出了一个500异常,具体提示的是IO 异常, 什么玩意, 有点蒙圈。

后经过排查发现是 jackson 下面 JsonMappingException 这个 类继承了 IoException, 系统中切换 并未打印出异常的详细信息,导致没有及时的发现问题的根源所在。

打印出详细信息后发现:

No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: org.springframework.data.domain.PageImpl["content"]->java.util.Collections$UnmodifiableRandomAccessList[0]->com.hdsxtech.rcyh.entity.YhjhYdjhb["ydjhzb"]->com.hdsxtech.rcyh.entity.YhjhYdjhzb_$$_jvstbff_a["handler"])

给人第一印象就是 里面有嵌套的对象 , 循环序列化了,

使用 @JsonIgorn 属性 添加到不需要序列化的 属性上, 结果又报了一个错

Caused by: com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: org.springframework.data.domain.PageImpl["content"]->java.util.Collections$UnmodifiableRandomAccessList[0]->com.hdsxtech.rcyh.entity.YhjhYdjhb["ydjhzb"]->com.hdsxtech.rcyh.entity.YhjhYdjhzb_$$_jvstf80_a["handler"])

百度了一下, 简单说由hibernate 懒加载引起

@ManyToOne(fetch=FetchType.EAGER,cascade=CascadeType.REFRESH)
    @JoinColumn(name = "jhzbid")
	private YhjhYdjhzb ydjhzb;   

将fetch 属性 有Lazy 改为Eager , 问题暂时的得到解决




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值