HttpMessageNotWritableException: Could not write JSON: No serializer found for class ****


今天碰到一個異常,下面是錯誤信息

org.springframework.http.converter.HttpMessageNotWritableException:   
Could not write JSON: 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) )   

根據提示,大致的意思應該是City類在轉化為json時,有屬性值是null,最后我在City類中加入了下面的一句代碼

@JsonIgnoreProperties({ "handler","hibernateLazyInitializer" })
問題得到了解決,需要值得注意的是:我的工程中有兩個JsonIgnoreProperties注解,分別是:
org.codehaus.jackson.annotate.JsonIgnoreProperties;
和com.fasterxml.jackson.annotation.JsonIgnoreProperties;
應該使用com.fasterxml.jackson.annotation.JsonIgnoreProperties;
參考:http://blog.csdn.net/switch_zyp/article/details/50633629


免責聲明!

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



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