hibernate对象懒加载,json序列化失败
2017-09-15 15:36
483 查看
//net.sf.json 解决办法 JsonConfig config = new JsonConfig(); config.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT); config.setExcludes(new String[]{"handler","hibernateLazyInitializer"}); //原文:https://zhidao.baidu.com/question/504539752.html ``` //fastjson解决办法 ```package com.pbh.aop; import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.LazyInitializer; import com.alibaba.fastjson.serializer.PropertyFilter; public class SimplePropertyFilter implements PropertyFilter { @Override public boolean apply(Object object, String name, Object value) { if (value instanceof HibernateProxy) {//hibernate代理对象 LazyInitializer initializer = ((HibernateProxy) value).getHibernateLazyInitializer(); if (initializer.isUninitialized()) { return false; } } else if (value instanceof PersistentCollection) {//实体关联集合一对多等 PersistentCollection collection = (PersistentCollection) value; if (!collection.wasInitialized()) { return false; } Object val = collection.getValue(); if (val == null) { return false; } } return true; } } <div class="se-preview-section-delimiter"></div>
String json = JSON.toJSONString(tags, filter);
http://blog.csdn.net/xiaozaq/article/details/53560000
``` SimplePropertyFilter filter = new SimplePropertyFilter(); String json = JSON.toJSONString(tags, filter);
原文:http://blog.csdn.net/xiaozaq/article/details/53560000
相关文章推荐
- hibernate + spring mvc,解决Hibernate对象懒加载,json序列化失败
- hibernate+spring mvc,解决hibernate对象懒加载,json序列化失败
- hibernate+spring mvc,解决hibernate对象懒加载,json序列化失败
- Spring MVC返回hibernate对象序列化json报懒加载出错的问题
- fastjson序列化hibernate持久化对象时忽略代理的懒加载对象
- fastjson序列化hibernate代理和延迟加载对象出现no session异常的解决办法
- hibernate+spring mvc, 解决hibernate 对象懒加载 json序列化问题
- fastjson序列化hibernate代理和延迟加载对象出现no session异常的解决办法
- fastjson序列化hibernate代理和延迟加载对象出现no session异常的解决办法
- 解决因为hibernate的懒加载引起的json 序列化失败的问题
- jackson json数据过滤,用于hibernate的懒加载对象级联关系的json解析
- hibernate中json序列化对象时lazy已关闭异常的处理
- SpringMVC、Hibernate系列之级联对象的json序列化
- struts2 json插件返回hibernate延迟加载对象过多卡死问题
- 自己编写的一个Json工具类,实现了反射将整个Object转换为Json对象的功能,支持Hibernate的延迟加载对象[修订081217]
- json解决hibernate中级联对象延迟加载问题net.sf.json.JSONException: org....
- json解决hibernate中级联对象延迟加载有关问题
- SpringMVC、Hibernate系列之级联对象的json序列化
- 序列化hibernate代理和延迟加载对象出现no session异常的解决办法
- hibernate懒加载和json序列化冲突