You can redefine root http://struts.apache.org/release/2.3.x/docs/json-plugin.html#JSONPlugin-RootObject
2014-11-05 12:13 GMT+01:00 Pavel Ilyushko <pavel.ilyus...@gmail.com>: > Hello there! > > Recently I've upgraded our struts2 framework and its related plugins (eg: > json plugin) from version 2.1.8 to version 2.3.16.3. > > Now I'm having problems in using the json plugin while making json requests > and returning the json responses. > > The problem is that the parameter values passed in the json request are not > set on my struts 2 action any more (likewise, the return fields set in my > action are not returned as a json string). > Why does this happen? The problem is that a change has been made in the > newer version of json plugin regarding to how the target action is found. > > 1. Consider this method: > > public String intercept(ActionInvocation invocation) throws Exception > > from the older version of the json plugin: > > http://grepcode.com/file/repo1.maven.org/maven2/org.apache.struts/struts2-json-plugin/2.1.8/org/apache/struts2/json/JSONInterceptor.java?av=f > > line 100: > > rootObject = invocation.getAction(); // that's why the action class > instance is found ok in struts 2.1.8 > > now from the newer plugin: > > http://grepcode.com/file/repo1.maven.org/maven2/org.apache.struts/struts2-json-plugin/2.3.16.3/org/apache/struts2/json/JSONInterceptor.java?av=f > > line 91: > > ValueStack stack = invocation.getStack(); > rootObject = stack.findValue(this.root); // the value on the top of the > value stack is used! and this is not an action in our case (we push an > interceptor on the top of the stack!). > > 2. Returning the target action's fields as the json return result: > > consider this method: > > public void execute(ActionInvocation invocation) throws Exception > > from the older plugin: > > http://grepcode.com/file/repo1.maven.org/maven2/org.apache.struts/struts2-json-plugin/2.1.8/org/apache/struts2/json/JSONResult.java?av=f > > line 195: > > rootObject = invocation.getAction(); // that's why the action class > instance is found in struts 2.1.8 > > from the newer plugin: > > http://grepcode.com/file/repo1.maven.org/maven2/org.apache.struts/struts2-json-plugin/2.3.16.3/org/apache/struts2/json/JSONResult.java?av=f > > line 175: > > rootObject = readRootObject(invocation); > > line 187: > > return findRootObject(invocation); > > line 193: > > ValueStack stack = invocation.getStack(); > rootObject = stack.findValue(root); // the value on the top of the value > stack is an instance of our custom interceptor, not the target action! > > It is not clear to me why the logic of finding the target action has > changed to popping up the value from the top of the stack. > > In our case this approach does not work anymore, since we have a custom > interceptor pushed onto the top of the stack. > > Is there any workaround? > > Thanks > > > > -- > Pavel Ilyushko --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org