title: How to ask gson to avoid escaping json in a json response?
body: <p>I have a response object like this:</p>
  
  <pre><code>public class TestResponse {
  
      private final String response;
      private final ErrorCodeEnum error;
      private final StatusCodeEnum status;
  
      // .. constructors and getters here
  }
  </code></pre>
  
  <p>I am serializing above class using Gson library as shown below:</p>
  
  <pre><code>Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls().create();
  System.out.println(gson.toJson(testResponseOutput));
  </code></pre>
  
  <p>And the response I am getting back is shown below:</p>
  
  <pre><code>{
    "response": "{\"hello\":0,\"world\":\"0\"}",
    "error": "OK",
    "status": "SUCCESS"
  }
  </code></pre>
  
  <p>As you can see, my json string in <code>"response"</code> field is getting escaped. Is there any way I can ask gson not to do that and instead return a full response like this:</p>
  
  <pre><code>{
    "response": {"hello":0,"world":"0"},
    "error": "OK",
    "status": "SUCCESS"
  }
  </code></pre>
  
  <p>And also - Is there any problem if I do it above way?</p>
  
  <p><strong>NOTE:</strong> My <code>"response"</code> string will always be JSON string or it will be null so only these two values will be there in my <code>"response"</code> string. In <code>"response"</code> field, I can have any json string since this library is calling a rest service which can return back any json string so I am storing that in a string <code>"response"</code> field.</p>