太常见的问题了,
该异常有两种解决方法:
第一:在struts.xml文件的配置中排除不要被JSON序列化的属性,例如:
<action name="functions" class="getFunctionsAction" method="functions_getList">
<result
type="json">
<param
name="excludeProperties">functionsService</param>
</result>
</action>
其中functionsService就是不要被JSON序列化的属性。
第二:在Action文件中去除不要被JSON序列化的属性的get()方法,例如:
public IFunctionsService getFunctionsService() {
return
functionsService;
}
这样做functionsService同样不会被JSON序列化。
说明:
带有transient修饰符与没有Getter方法的字段(field)都不会被串行化为JSON。
不行就新建个action即可解决。
该异常有两种解决方法:
第一:在struts.xml文件的配置中排除不要被JSON序列化的属性,例如:
<action name="functions" class="getFunctionsAction" method="functions_getList">
其中functionsService就是不要被JSON序列化的属性。
第二:在Action文件中去除不要被JSON序列化的属性的get()方法,例如:
public IFunctionsService getFunctionsService() {
这样做functionsService同样不会被JSON序列化。
说明:
带有transient修饰符与没有Getter方法的字段(field)都不会被串行化为JSON。
不行就新建个action即可解决。
本文详细介绍了在使用Struts框架时遇到的JSON序列化问题,并提供了两种解决策略:通过在struts.xml配置文件中排除不需要序列化的属性,或者在Action文件中去除这些属性的getter方法。同时解释了带有transient修饰符和没有getter方法的字段不会被序列化的原因。
2456

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



