I have a RestService in which I am returning a JSON response as shown below.
Below is my code:
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
@GET
@Path("/json/lime")
@Produces(MediaType.APPLICATION_JSON)
public DataResponse getData(@Context DataInfo info) {
// some code here
System.out.println(resp.getResponse());
return new DataResponse(resp.getResponse());
}
Below is the actual JSON response I get back after hitting my Restful Service:
{
"response": "{\"ABC\":100,\"PQR\":\"40\"}\n",
}
And this is what it gets printed out from System.out as shown above:
{"ABC":100,"PQR":"40"}
Here is my DataResponse
class:
public class DataResponse {
private String response;
public DataResponse(String response) {
this.response = response;
}
public String getResponse() {
return this.response;
}
}
As you can see, my response
string is getting escaped in the above JSON. And I am not sure why? Can anyone help me understand why this is happening and how to fix it?