MyBatis 解决No serializer found for class org.apache.ibatis.executor.loader.javassist.JavassistProxyFactory$EnhancedResultObjectProxyImpl and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)
的三种方法
- fetchtype=eager
关闭懒加载 - @JsonIgnoreProperties(value = { “handler” })
忽略序列化时一些问题
@JsonIgnoreProperties(value = { "handler" })
public class SysRole implements Serializable {
private Long id;
private String name;
这是因为报错的具体提示而定的
{
"timestamp": "2020-03-07T07:46:51.739+0000",
"status": 500,
"error": "Internal Server Error",
"message": "Type definition error: [simple type, class org.apache.ibatis.executor.loader.javassist.JavassistProxyFactory$EnhancedResultObjectProxyImpl]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.apache.ibatis.executor.loader.javassist.JavassistProxyFactory$EnhancedResultObjectProxyImpl and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: cn.hcnet2006.blog.hcnetwebsite.http.HttpResult[\"data\"]->cn.hcnet2006.blog.hcnetwebsite.pages.PageResult[\"content\"]->com.github.pagehelper.Page[0]->cn.hcnet2006.blog.hcnetwebsite.bean.SysRole_$$_jvste63_0[\"handler\"])",
"path": "/role/find/page"
}
最终说明是由于SysRole中“handler”属性序列化失败造成的,具体原因又是因为FAIL_ON_EMPTY_BEANS,生成空bean失败
因此可以忽略SysRole这一个实体类中所有序列与饭序列的失败
- 修改Json
接第二种方法
因为是FAIL_ON_EMPTY_BEANS
所以序列化的时后,空的bean一起显示就可以
代码若下
jackson:
serialization:
FAIL_ON_EMPTY_BEANS: false
当我得到结果的时候显示handler为空截取一部分
],
"handler": {}
},
- 总结
根据2和3说明懒加载序列化的时候会生成一个handler的空bean,2和三从不同的角度对他进行了解决,这就是我的理解
不过我现在分页查询还是显示一块加载,我在看看
突然想分页加载我要嵌套查询做什么呢,傻了