今天碰到一個異常,下面是錯誤信息
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