在使用struts2的json-plugin时,如果要序列化一个Action,应该屏蔽掉不需要序列化的属性,比如dao等。

尤其是Dao,如果不屏蔽,将会导致

如下的错误:

org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetExceptionorg.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetExceptionpache.struts2.json.JSONException:

屏蔽的方法很简单:不要给该要屏蔽的属性设置getter

或者 在要屏蔽的属性的getter前加上注解 @JSON(serialize = false) 这种方法

@JSON(serialize = false)
	public UserDao getUserDao() {
		return userDao;
	}