No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no pro

No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no pro_第1张图片

数据已经从数据库查询出来了,但是返回的时候还是会报错No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer,但是查看实体明明已经序列化了但是为什么不生效呢

答案是因为Hibernate的延迟加载所以这里是个Hibernate的代理对象。该代理对象有些属性不能被序列化所以会报错

在类型上加注解把不需要序列化的属性屏蔽掉 添加注解@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })

No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no pro_第2张图片

你可能感兴趣的:(java)