Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Co
2017-12-14 10:53
567 查看
Failed to write HTTP message: 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); 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: com.Controller.User_$$_jvstdcc_0["handler"])
在spring boot框架中出通过id查询数据的时候出现的这个问题,
是因为查询的数据返回时空出现的异常:
使用来个一个注解,添加在实体类上就可以解决了
这个注解的含义:
在此标记不生成json对象的属性
因为jsonplugin用的是java的内审机制.hibernate会给被管理的pojo加入一个hibernateLazyInitializer属性,jsonplugin会把hibernateLazyInitializer也拿出来操作,并读取里面一个不能被反射操作的属性就产生了这个异常.
不过我用的是jackson来转json,所以想到了用annotation来排除hibernateLazyInitializer 这个属性
在你的pojo类声明加上:
[java]
view plain
copy
@JsonIgnoreProperties(value={"hibernateLazyInitializer"})
[java]
view plain
copy
@JsonIgnoreProperties就是标注 哪个属性 不用转化为json的
(to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS); 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: com.Controller.User_$$_jvstdcc_0["handler"])
在spring boot框架中出通过id查询数据的时候出现的这个问题,
是因为查询的数据返回时空出现的异常:
使用来个一个注解,添加在实体类上就可以解决了
@JsonIgnoreProperties({ "handler","hibernateLazyInitializer" })
这个注解的含义:
在此标记不生成json对象的属性
因为jsonplugin用的是java的内审机制.hibernate会给被管理的pojo加入一个hibernateLazyInitializer属性,jsonplugin会把hibernateLazyInitializer也拿出来操作,并读取里面一个不能被反射操作的属性就产生了这个异常.
不过我用的是jackson来转json,所以想到了用annotation来排除hibernateLazyInitializer 这个属性
在你的pojo类声明加上:
[java]
view plain
copy
@JsonIgnoreProperties(value={"hibernateLazyInitializer"})
[java]
view plain
copy
@JsonIgnoreProperties就是标注 哪个属性 不用转化为json的
相关文章推荐
- Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Cou
- org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Infinite r
- Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Cou
- org.springframework.http.converter.HttpMessageNotWritableException:
- 经检查,各种没问题,但是前台500。后台org.springframework.http.converter.HttpMessageNotWritableException
- org.springframework.http.converter.HttpMessageNotWritableException:
- [Spring+MyBatis3]关联查询(延迟加载)抛错误 org.springframework.http.converter.HttpMessageNotWritableException
- org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing
- org.springframework.http.converter.HttpMessageNotReadableException: Could not read document:
- SSM框架搭建java.lang.ClassNotFoundException: org.springframework.http.converter.json.MappingJacksonHttpMessageConverter
- java.lang.ClassNotFoundException: org.springframework.http.converter.json.MappingJacksonHttpMessageC
- Crash-fix-2:org.springframework.http.converter.HttpMessageNotReadableException
- Spring 4.x org.springframework.http.converter.json.MappingJacksonHttpMessageConverter ClassNotFoundException:
- java.lang.ClassNotFoundException: org.springframework.http.converter.json.MappingJacksonHttpMessageC
- Not found org.springframework.http.converter.json.MappingJacksonHttpMessageConverter
- org.springframework.remoting.RemoteConnectFailureException: Could not connect to HTTP invoker remote
- Spring 整合 Flex (BlazeDS)无法从as对象 到 Java对象转换的异常:org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.util.Date' to required type 'java.sql.Timestamp' for property 'wfsj'; nested exception is java.lang.Ill
- Not found org.springframework.http.converter.json.MappingJacksonHttpMessageConverter
- Not found org.springframework.http.converter.json.MappingJacksonHttpMessageConverter
- org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'java.la