title: Getting JSON object from Java in Struts 2
body: <p>I am trying to get response text from Java server using <code>getJSON()</code> jQuery method. Although, I can get response data  when the Java class is simple format  (<code>String</code>, <code>List</code> and <code>Map</code>), I could not get success data when using other Java object.</p>
  <p>The following is Java class which is using a simple type and I get the success result with data that works:</p>
  <pre class="lang-java prettyprint-override"><code>package com.awitd.framework.action;
  
  import com.opensymphony.xwork2.Action;
  
  public class getAllJson implements Action{
  
  private String data;
  
  public String getData() {
      return data;
  }
  
  public void setData(String data) {
      this.data = data;
  }
  
  public String execute() {
      System.out.println(&quot; this is from action&quot;);
      data = &quot;[&quot;;
              data += &quot;{&quot;;
              data += &quot;\&quot;objid\&quot;:\&quot;&quot; + &quot;1&quot; + &quot;\&quot;,&quot;;
              data += &quot;\&quot;id\&quot;:\&quot;&quot; + &quot;1&quot; + &quot;\&quot;,\&quot;name\&quot;:\&quot;&quot; + &quot;name&quot; + &quot;\&quot;&quot;;
              data += &quot;}&quot;; System.out.println(&quot;data &quot; + data);
          
      data += &quot;]&quot;;
      
      return SUCCESS;
  }
  
  
  }
  </code></pre>
  <p>The following is Java class which is using other Java object and it doesn't return a success data:</p>
  <pre class="lang-java prettyprint-override"><code>package com.awitd.framework.action;
  
  import java.util.List;
  
  import com.opensymphony.xwork2.Action;
  import com.awitd.framework.entity.Employee;
  import com.awitd.framework.entity.Profile;
  import com.awitd.framework.service.EmployeeService;
  public class getAllJson implements Action{
  
  private String data;
  
  private EmployeeService employeeService;
  
  
  
  private List&lt;Employee&gt; employeeList;
  private Employee employee;
  private Profile profile;
  public String getData() {
      return data;
  }
  
  public void setData(String data) {
      this.data = data;
  }
  
  public EmployeeService getEmployeeService() {
      return employeeService;
  }
  
  public void setEmployeeService(EmployeeService employeeService) {
      this.employeeService = employeeService;
  }
  
  public String execute() {
      System.out.println(&quot; this is from action&quot;);
      data = &quot;[&quot;;
              /*data += &quot;{&quot;;
              data += &quot;\&quot;objid\&quot;:\&quot;&quot; + &quot;1&quot; + &quot;\&quot;,&quot;;
              data += &quot;\&quot;id\&quot;:\&quot;&quot; + &quot;1&quot; + &quot;\&quot;,\&quot;name\&quot;:\&quot;&quot; + &quot;name&quot; + &quot;\&quot;&quot;;
              data += &quot;}&quot;; System.out.println(&quot;data &quot; + data);*/
          
  
      
      employeeList = employeeService.getAll();    
      System.out.println(&quot;size........&quot;+employeeList.size()); 
      if (!employeeList.isEmpty()) {
          for (int i=0; i&lt;employeeList.size(); i++) {
              employee = employeeList.get(i);
              profile = employee.getProfile();
              data += &quot;{&quot;;
              data += &quot;\&quot;objid\&quot;:\&quot;&quot; + employee.getEmployeeId() + &quot;\&quot;,&quot;;
              data += &quot;\&quot;id\&quot;:\&quot;&quot; + employee.getId() + &quot;\&quot;,\&quot;name\&quot;:\&quot;&quot; + employee.getName() + &quot;\&quot;&quot;;
              data += &quot;,\&quot;dob\&quot;:\&quot;&quot; + profile.getDob() + &quot;\&quot;,\&quot;sex\&quot;:\&quot;&quot; + profile.getSex() + &quot;\&quot;&quot;;
              data += &quot;,\&quot;email\&quot;:\&quot;&quot; + profile.getEmail() + &quot;\&quot;,\&quot;workstart\&quot;:\&quot;&quot; + profile.getWorkstart() + &quot;\&quot;&quot;;
              data += &quot;,\&quot;study\&quot;:\&quot;&quot; + profile.getStudySub() + &quot;\&quot;,\&quot;jplevel\&quot;:\&quot;&quot; + profile.getJpLevel() + &quot;\&quot;&quot;;
              data += &quot;,\&quot;jpgroup\&quot;:\&quot;&quot; + profile.getJpGroup() + &quot;\&quot;,\&quot;remark\&quot;:\&quot;&quot; + profile.getRemark() + &quot;\&quot;&quot;;
              data += &quot;}&quot;;
              if (!(i==employeeList.size()-1))
                  data += &quot;,&quot;; 
          }
      }
      data += &quot;]&quot;;
      
      
      
      
      return SUCCESS;
  }
  
  
   }
  </code></pre>
  <p><strong>Got this error:</strong></p>
  <pre><code>No existing transaction found for transaction marked with propagation 'mandatory'
  
  java.lang.reflect.InvocationTargetException    
  org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException:
  org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException
  org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:246)
  org.apache.struts2.json.JSONWriter.processCustom(JSONWriter.java:178)
  org.apache.struts2.json.JSONWriter.process(JSONWriter.java:168)
  org.apache.struts2.json.JSONWriter.value(JSONWriter.java:134)
  org.apache.struts2.json.JSONWriter.write(JSONWriter.java:102)
  org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:116)
  org.apache.struts2.json.JSONResult.createJSONString(JSONResult.java:196)
  org.apache.struts2.json.JSONResult.execute(JSONResult.java:170)
  com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:367)
  com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:271)
  </code></pre>