title: How to exclude param from response in struts 2 and send the object we want?
body: <p>I want JSON result for Ajax request, but my requirement is to send only the <code>ArrayList</code> of object and exclude some of the parameter present in action class. So how to do this?</p>
  
  <p>This is my action class</p>
  
  <pre><code>public class AjaxAction{
      private  int color;
      private  String prodId;
      private List&lt;Product&gt; productList;
  
  
      public String execute(){
      productList= service.getProductList();//this method is getting list of products
      HttpServletResponse response = ServletActionContext.getResponse();
  
      Gson gson = new Gson();
      JsonElement element = gson.toJsonTree(productList,
              new TypeToken&lt;List&lt;Product&gt;&gt;() {
              }.getType());
      JsonArray jsonArray = element.getAsJsonArray();
      response.setContentType("application/json");
      try {
          response.getWriter().print(jsonArray);
      } catch (IOException e) {
          e.printStackTrace();
      }
      return "success";
  }
  </code></pre>
  
  <p>And my <code>struts.xml</code> file is:</p>
  
  <pre><code>&lt;package name="json" namespace="/" extends="json-default"&gt;
      &lt;interceptors&gt;
          &lt;interceptor-stack name="mystack"&gt;
              &lt;interceptor-ref name="defaultStack" /&gt;
              &lt;interceptor-ref name="json"&gt;
                  &lt;param name="enableSMD"&gt;true&lt;/param&gt;
              &lt;/interceptor-ref&gt;
          &lt;/interceptor-stack&gt;
      &lt;/interceptors&gt;
      &lt;action name="getProduct" class="com.xyz.action.AjaxAction"&gt;
          &lt;result name="success" type="json" /&gt;
          &lt;param name="root"&gt;productList&lt;/param&gt;
      &lt;/action&gt;
  &lt;/package&gt;
  </code></pre>
  
  <p>So when i check my console data returned from action is having other variable in it. How to avoid that?</p>