title: gson.toJson(jObj) stackoverflowerror .TypeAdapters$25.write(TypeAdapters.java:704)
body: <p>I am trying to convert a json object to String using gson. Below is the code</p>
  
  <pre><code>List&lt;Student&gt; studs = //from db
          int count = studs.size();
          Integer tot_pages= count/limit;
          if(page&gt;tot_pages){
              page=tot_pages;
          }
          Integer start=limit*page-limit;
          Gson gson = new Gson();
          JsonObject jObj= new JsonObject();
          jObj.addProperty("page", page);
          jObj.addProperty("total",tot_pages);
          jObj.addProperty("records",count);
          JsonArray cell = new JsonArray();
          JsonArray rows = new JsonArray();
          JsonObject row= new JsonObject();
          for(Student stud: studs){
              row= new JsonObject();
              row.addProperty("id", stud.getId());
              cell=new JsonArray();
              JsonPrimitive name = new JsonPrimitive(stud.getName());
              JsonPrimitive rollno = new JsonPrimitive(stud.getRollno());
              JsonPrimitive yr = new JsonPrimitive(stud.getYr());
              cell.add(name);
              cell.add(rollno);
              cell.add(yr);
              row.add("cell", row);
              rows.add(row);
              System.out.println(stud.getId());
          }
          System.out.println("done");
  
          jObj.add("rows", rows);
          System.out.println("done1");
          return gson.toJson(jObj);
  </code></pre>
  
  <p>and getting the error below</p>
  
  <blockquote>
    <p>Caused by: java.lang.StackOverflowError   at
    java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:416)
      at java.lang.StringBuffer.append(StringBuffer.java:237)     at
    java.io.StringWriter.write(StringWriter.java:101)     at
    com.google.gson.stream.JsonWriter.string(JsonWriter.java:534)     at
    com.google.gson.stream.JsonWriter.writeDeferredName(JsonWriter.java:402)
      at com.google.gson.stream.JsonWriter.value(JsonWriter.java:495)     at
    com.google.gson.internal.bind.TypeAdapters$25.write(TypeAdapters.java:686)
      at
    com.google.gson.internal.bind.TypeAdapters$25.write(TypeAdapters.java:704)
      at
    com.google.gson.internal.bind.TypeAdapters$25.write(TypeAdapters.java:704)
      at
    com.google.gson.internal.bind.TypeAdapters$25.write(TypeAdapters.java:704)
      at
    com.google.gson.internal.bind.TypeAdapters$25.write(TypeAdapters.java:704)
      at
    com.google.gson.internal.bind.TypeAdapters$25.write(TypeAdapters.java:704)
      at
    com.google.gson.internal.bind.TypeAdapters$25.write(TypeAdapters.java:704)   &lt;-----this line is repeated many times.</p>
  </blockquote>
  
  <p>please someone help me out.</p>