zoukankan      html  css  js  c++  java
  • 【实体 报错 】No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer

    1 HTTP Status 500 - Could not write content: 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: java.util.ArrayList[0]->com.agen.entity.User["positionchanges"]->org.hibernate.collection.internal.PersistentSet[0]->com.agen.entity.Positionchange["position"]->com.agen.entity.Position_$$_jvst714_7["handler"]); nested exception is 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: java.util.ArrayList[0]->com.agen.entity.User["positionchanges"]->org.hibernate.collection.internal.PersistentSet[0]->com.agen.entity.Positionchange["position"]->com.agen.entity.Position_$$_jvst714_7["handler"])
    View Code

    解决方式:

    1.可以将报错位置的

    修改为

    这是一种解决方式!

    2.网友解决方法

    hibernate会给每个被管理的对象加上hibernateLazyInitializer属性,同时struts-jsonplugin或者其他的jsonplugin都是

    因为jsonplugin用的是java的内审机制.hibernate会给被管理的pojo加入一个hibernateLazyInitializer属性,jsonplugin通过java的反射机制将pojo转换成json,会把hibernateLazyInitializer也拿出来操作,但是hibernateLazyInitializer无法由反射得到,所以就抛异常了。 

    所以在我的pojo类上加上如下声明:

    @JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"}) 

    @JsonIgnoreProperties(value={"hibernateLazyInitializer"})   (此时只是忽略hibernateLazyInitializer属性)要加载被lazy的,也就是many-to-one的one端的pojo上

    这行代码的作用在于告诉你的jsonplug组件,在将你的代理对象转换为json对象时,忽略value对应的数组中的属性,即:

    通过java的反射机制将pojo转换成json的,属性,(通过java的反射机制将pojo转换成json的,)

    "hibernateLazyInitializer","handler","fieldHandler",(如果你想在转换的时候继续忽略其他属性,可以在数组中继续加入)

  • 相关阅读:
    用智慧明辨之
    做一个成功的软件架构师需要哪些素质?
    如何成为一名优秀的产品经理
    项目管理中的冲突管理
    .Net 缓存依赖详解
    从程序制作到构架制作
    如何做好一名软件团队的领导者
    需求变更的代价
    页面缓存的实现
    项目风险盘点
  • 原文地址:https://www.cnblogs.com/sxdcgaq8080/p/6364736.html
Copyright © 2011-2022 走看看