Hi there! Thanks for a swift reply.
Actually, re-defining the root is what I applied as a work-around. So in my struts.xml I have this (to fix setting the parameters on the action): <interceptor-ref name="json"> <param name="root">action</param> </interceptor-ref> and also for each json action type I have this (to set the action fields for json response) : <result type="json"> <param name="root">action</param> </result> Note, I'm using 'action' as the root. I found this in the code: http://grepcode.com/file/repo1.maven.org/maven2/org.apache.struts.xwork/xwork-core/2.3.16.3/com/opensymphony/xwork2/DefaultActionInvocation.java?av=f see code for public void <http://grepcode.com/file/repo1.maven.org/maven2/org.apache.struts.xwork/xwork-core/2.3.16.3/com/opensymphony/xwork2/DefaultActionInvocation.java?av=f#>init <http://grepcode.com/file/repo1.maven.org/maven2/org.apache.struts.xwork/xwork-core/2.3.16.3/com/opensymphony/xwork2/ActionInvocation.java#ActionInvocation.init%28com.opensymphony.xwork2.ActionProxy%29>(ActionProxy <http://grepcode.com/file/repo1.maven.org/maven2/org.apache.struts.xwork/xwork-core/2.3.16.3/com/opensymphony/xwork2/ActionProxy.java#ActionProxy> proxy) method, line 401: if (pushAction) { stack.push(action); contextMap.put("action", action); } As you can see, the "action" key is hard coded and specified nowhere in the official struts 2 doc. So it's kind of dangerous to rely on this key, since it might change in the future without notification. Is there a cleaner way to redefine the root, as you've suggested? Thanks! Pavel On Wed, Nov 5, 2014 at 12:54 PM, Lukasz Lenart <lukaszlen...@apache.org> wrote: > You can re-define 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 > > -- Pavel Ilyushko