java - How to pass raw JSON as a response from Restful service? -


i have restservice in returning json response shown below.

below 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) {      // code here     system.out.println(resp.getresponse());     return new dataresponse(resp.getresponse()); } 

below actual json response after hitting restful service:

{     "response": "{\"abc\":100,\"pqr\":\"40\"}\n", } 

and gets printed out system.out shown above:

{"abc":100,"pqr":"40"} 

here dataresponse class:

public class dataresponse {      private string response;      public dataresponse(string response) {         this.response = response;     }      public string getresponse() {         return this.response;     } } 

as can see, response string getting escaped in above json. , not sure why? can me understand why happening , how fix it?

use response class:

import javax.ws.rs.get; import javax.ws.rs.path; import javax.ws.rs.produces; import javax.ws.rs.core.response;      @get     @path("/json/lime")     @produces(mediatype.application_json)     public responsegetdata(@context datainfo info) {         ...         return response.status(200).entity(resp.getresponse()).build();     } 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -