SSM整合下mybatis启用懒加载拿到解决正确但JSON序列化异常:No serializer found for class XXX and no properties...

因为第一次自己做vue + SSM + Oracle项目,碰到各种稀奇古怪的问题,这一次又花了好几个小时解决了…(头大)

  • 可能问题1:起初看到spring boot很多文章讲到序列化对象的值为空或没有set/get方法(我不是该问题)
  • 可能问题2:懒加载

参考文章:https://blog.csdn.net/dange_h/article/details/105839699

  • 总而言之:Bug原因是-因为mybatis的懒加载原因
    <resultMap id="order" type="order">
        <id property="id" column="id" />
        <result property="orderNum" column="orderNum" />
        <result property="orderTime" column="orderTime" />
        <result property="orderStatus" column="orderStatus" />
        <result property="peopleCount" column="peopleCount" />
        <result property="payType" column="payType" />
        <result property="orderDesc" column="orderDesc" />
        <association column="productId" property="product"
                     select="top.jybill.dao.IProductDao.findProductById"
                     fetchType="eager" />
    </resultMap>

起初我没有fetchType属性,默认是lazy懒加载, 修改成eager后成功序列化了
在这里插入图片描述

  • 因为我是一对一的,一般情况不需要懒加载,如果是一对多必须懒加载的情况参考上面的链接
    添加@JsonIgnoreProperties(value = "handler")注解
    Unable to serialize claims object to json: Unable to serialize object: No serializer found for class org.apache.ibatis.executor.loader.javassist.JavassistProxyFactory$EnhancedResultObjectProxyImpl and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: io.jsonwebtoken.impl.DefaultClaims[\"userInfo\"]->top.jybill.domain.MyUser_$$_jvst2e5_0[\"handler\"])
    我的报错如上:
    我将相关的实体类全部加上了@JsonIgnoreProperties(value = "handler")然后就正常了
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值