在使用Json-Lib将Java对象转成JsonString时,一般情况下,我们都使用JSONObject.fromObject(Java 对象) 就可以了。但是在使用hibernate来操作数据库得到对象进行转换时就会抛出异常。
异常为:
JSONObject.fromObject(hibernate对象)
出现以下Exception
net.sf.json.JSONException:
java.lang.reflect.InvocationTargetException
net.sf.json.JSONObject._fromBean(JSONObject.java:959)
detaiMessage:Positioned Update not supported
net.sf.json.JSONObject._fromBean(JSONObject.java:959)
detaiMessage:Positioned Update not supported
解决方法如下 :使用以下代码来
JsonConfig jsonConfig=new
JsonConfig();
jsonConfig.setExcludes(new String[]{"handler","hibernateLazyInitializer"});
JSONObject.fromObject(hibernate对象,jsonConfig);
jsonConfig.setExcludes(new String[]{"handler","hibernateLazyInitializer"});
JSONObject.fromObject(hibernate对象,jsonConfig);
本文介绍了一种在使用Json-Lib将Hibernate对象转换为JSON字符串时遇到的问题及解决方案。当直接转换时可能会出现异常,文章提供了一种通过配置JsonConfig来排除特定属性的方法避免异常。
3566

被折叠的 条评论
为什么被折叠?



