异常形式: class org.apache.struts2.json.jsonwriter can not access a member of * 或是 class com.googlecode.jsonplugin.jsonwriter can not access a member of class* 第一种是struct2.1.8与json结合时的异常,第二种是struct2.1.6与json结合的异常。
异常形式:
class org.apache.struts2.json.jsonwriter can not access a member of * 或是 class com.googlecode.jsonplugin.jsonwriter can not access a member of class*
第一种是struct2.1.8与json结合时的异常,第二种是struct2.1.6与json结合的异常。
具体:
class org.apache.struts2.json.jsonwriter can not access a member of class oracle.jdbc.driver.baseresultset with modifiers public
解释:
不能把程序中的某种数据结构串行化成json格式。
原因:
struts2的action里面的数据转换成json数据时,会将提供了get方法的属性都串行化输出json到客户端。有的时候,很多属性并不能串行化成json数据,比如这里的oracle.jdbc.driver.baseresultset。这时还进行强行转换就会出现这样的异常。
解决方法:
在不能串行化到json的属性相应的get方法前加一条json标记 @json(serialize=false)。告诉json不需要转化这个属性。或者根本不写这个get方法。
后记:
对于不需要在前台输出的json数据,也可以用同样的方法进行处理,从而减少服务器和客户端间交互的信息量。
可在需要在前台输出的属性的get方法前加上@json(name=status)标识,从而为该属性起了一个别名,在前台就可以通过status作为属性名来读取其值。