【實體 報錯 】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",(如果你想在轉換的時候繼續忽略其他屬性,可以在數組中繼續加入)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM