<原谅出处(http://www.educity.cn/wenda/123610.html)
使用jackson遇到的问题
后台不会报错,但是前台报:
<pre>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 SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference chain:
com.scm.common.utils.BaseResponse["content"]->java.util.HashMap["app"]-
>com.scm.pcManager.po.ScmApplicationmain["scmPcinfor"]->com.scm.pcManager.po.ScmPcinfor_$
$_javassist_22["handler"]); nested exception is org.codehaus.jackson.map.JsonMappingException: No serializer
found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create
BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference
chain: com.scm.common.utils.BaseResponse["content"]->java.util.HashMap["app"]-
>com.scm.pcManager.po.ScmApplicationmain["scmPcinfor"]->com.scm.pcManager.po.ScmPcinfor_$
$_javassist_22["handler"]
引起以下问题的主要原因就是jackson把懒加载也作为pojo进行序列化了。
解决方法:在实体类上加上
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})就OK了
使用jackson遇到的问题
后台不会报错,但是前台报:
<pre>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 SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference chain:
com.scm.common.utils.BaseResponse["content"]->java.util.HashMap["app"]-
>com.scm.pcManager.po.ScmApplicationmain["scmPcinfor"]->com.scm.pcManager.po.ScmPcinfor_$
$_javassist_22["handler"]); nested exception is org.codehaus.jackson.map.JsonMappingException: No serializer
found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create
BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference
chain: com.scm.common.utils.BaseResponse["content"]->java.util.HashMap["app"]-
>com.scm.pcManager.po.ScmApplicationmain["scmPcinfor"]->com.scm.pcManager.po.ScmPcinfor_$
$_javassist_22["handler"]
引起以下问题的主要原因就是jackson把懒加载也作为pojo进行序列化了。
解决方法:在实体类上加上
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})就OK了