title: Java StackOverflowError error when converting object to JSON
body: <p>I have the following Java object.</p>
  <pre><code>@XmlAccessorType(XmlAccessType.FIELD)
  @XmlType(
      name = &quot;ApprovalRequest&quot;,
      propOrder = {&quot;requiredConclusionTime&quot;, &quot;approvalType&quot;, &quot;businessRequest&quot;, &quot;supportingInfo&quot;, &quot;messageToEvaluator&quot;, &quot;organisation&quot;, &quot;resubmissionOf&quot;, &quot;requestedBy&quot;, &quot;nominatedEvaluator&quot;, &quot;evaluationStrategy&quot;}
  )
  public class ApprovalRequest implements Serializable {
      private static final long serialVersionUID = 1L;
      @XmlSchemaType(
          name = &quot;dateTime&quot;
      )
      protected XMLGregorianCalendar requiredConclusionTime;
      protected Integer approvalType;
      @XmlElement(
          required = true
      )
      protected Object businessRequest;
      protected List&lt;Object&gt; supportingInfo;
      protected String messageToEvaluator;
      @XmlElement(
          required = true
      )
      @XmlSchemaType(
          name = &quot;anyURI&quot;
      )
      protected String organisation;
      protected String resubmissionOf;
      protected PersonalInfo requestedBy;
      protected EvaluatorNomination nominatedEvaluator;
      protected EvaluationStrategy evaluationStrategy;
  
      public ApprovalRequest() {
      }
  
      public XMLGregorianCalendar getRequiredConclusionTime() {
          return this.requiredConclusionTime;
      }
  
      public void setRequiredConclusionTime(XMLGregorianCalendar value) {
          this.requiredConclusionTime = value;
      }
  
      public Integer getApprovalType() {
          return this.approvalType;
      }
  
      public void setApprovalType(Integer value) {
          this.approvalType = value;
      }
  
      public Object getBusinessRequest() {
          return this.businessRequest;
      }
  
      public void setBusinessRequest(Object value) {
          this.businessRequest = value;
      }
  
      public List&lt;Object&gt; getSupportingInfo() {
          if (this.supportingInfo == null) {
              this.supportingInfo = new ArrayList();
          }
  
          return this.supportingInfo;
      }
  
      public String getMessageToEvaluator() {
          return this.messageToEvaluator;
      }
  
      public void setMessageToEvaluator(String value) {
          this.messageToEvaluator = value;
      }
  
      public String getOrganisation() {
          return this.organisation;
      }
  
      public void setOrganisation(String value) {
          this.organisation = value;
      }
  
      public String getResubmissionOf() {
          return this.resubmissionOf;
      }
  
      public void setResubmissionOf(String value) {
          this.resubmissionOf = value;
      }
  
      public PersonalInfo getRequestedBy() {
          return this.requestedBy;
      }
  
      public void setRequestedBy(PersonalInfo value) {
          this.requestedBy = value;
      }
  
      public EvaluatorNomination getNominatedEvaluator() {
          return this.nominatedEvaluator;
      }
  
      public void setNominatedEvaluator(EvaluatorNomination value) {
          this.nominatedEvaluator = value;
      }
  
      public EvaluationStrategy getEvaluationStrategy() {
          return this.evaluationStrategy;
      }
  
      public void setEvaluationStrategy(EvaluationStrategy value) {
          this.evaluationStrategy = value;
      }
  }
  </code></pre>
  <p>When I do the following:</p>
  <pre><code>ApprovalRequest approvalRequest = new ApprovalRequest();
  Gson gson = new Gson();
  String approvalRequestJsonStr = gson.toJson(approvalRequest);
  </code></pre>
  <p>It works perfectly.</p>
  <p>However, when I let the application run on the JBoss server, and at runtime with a populated <code>ApprovalRequest</code>, there's an exception converting the object to JSON.</p>
  <pre><code>Gson gson = new Gson();
  String approvalRequestJsonStr = gson.toJson(approvalRequest);
  </code></pre>
  <p>Gets the following error:</p>
  <pre><code>Caused by: java.lang.StackOverflowError
  18:40:26,836 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.stream.JsonWriter.peek(JsonWriter.java:350)
  18:40:26,836 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.stream.JsonWriter.beforeName(JsonWriter.java:565)
  18:40:26,836 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.stream.JsonWriter.writeDeferredName(JsonWriter.java:386)
  18:40:26,836 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.stream.JsonWriter.value(JsonWriter.java:402)
  18:40:26,836 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.internal.bind.TypeAdapters$13.write(TypeAdapters.java:353)
  18:40:26,836 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.internal.bind.TypeAdapters$13.write(TypeAdapters.java:337)
  18:40:26,836 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
  18:40:26,836 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:89)
  18:40:26,837 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:195)
  18:40:26,837 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.internal.bind.ObjectTypeAdapter.write(ObjectTypeAdapter.java:105)
  18:40:26,837 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
  18:40:26,837 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:96)
  18:40:26,837 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:60)
  18:40:26,837 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
  18:40:26,837 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:89)
  ...
  </code></pre>
  <p>Any ideas how I can fix this?</p>