How to include parent class fields in json response using struts 2 json plugin

json, struts2

Solution

By default properties defined on base classes of the "root" object won't be serialized, to serialize properties in all base classes (up to Object) set "ignoreHierarchy" to false in the JSON result:

Something like

<result type="json">
  <param name="ignoreHierarchy">false</param>
</result>

For details refer to the JSON plugin documentation

- JSONPlugin-BaseClasses

Problem

I have following implementation ``` public abstract class BaseAcion extends ActionSupport { private String result; private String message; //getters, setters } public class MyAction extends BaseAction { private String myFirstField; private String mySecondField; public String execute() { ... myFirstField = "someValue"; mySecondField = "someOtherValue"; ... result = SUCCESS; message = "Some message here"; ... return result; } //methods, getters, setters } ``` I have used struts2-json plugin, action mapping is ``` <package name="my-package" namespace="/" extends="json-default" > <action name="myAction" class="MyAction"> <result type="json"></result> </action> </package> ``` The response that I receive is something like this. ``` { "myFirstField":"someValue", "mySecondField":"someOtherValue" } ``` I want to get "result" and "message" fields in response as well. How can I include BaseAction fields in json response?

Original source