mybatis懒加载 responsebody json序列化时候的异常

mybatis开启懒加载后,返回bean为json时,出现以下异常java

10:29:47.016 [http-apr-8088-exec-10] WARN  o.s.w.s.m.s.DefaultHandlerExceptionResolver - 
Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: 
Could not write content:
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) )

 

网上两种处理意见spring

1 继承ObjectMapper 设置属性为 SerializationFeature.FAIL_ON_EMPTY_BEANS 为false。 apache

2 在须要转json的实体类上加 @JsonInclude(JsonInclude.Include.NON_EMPTY)json

第二种方案有一个弊端 ,好比实体类中,存在一个integer为0 ,则json就不转化了mybatis

查找发现 对于hibeante有一种处理方式app

@JsonIgnoreProperties(value={“hibernateLazyInitializer”,”handler})hibernate

我认为 mybatis也应该能够有相似hibernate的处理方式debug

可是网上没有找到代理

debug观察须要处理的bean,发现多了一个属性code

应该是懒加载时候一个代理

尝试在转换时 忽略他@JsonIgnoreProperties(value = {"javassistProxyFactory", "handler"})

搞定

相关文章
相关标签/搜索