users@jersey.java.net

json object value string has extra quotes, jsonp, service chaining

From: stuart mellanby <stuart_mellanby_at_hotmail.com>
Date: Wed, 10 Jun 2009 22:13:14 +0000

My short question is why does my jsonp response have an extra set of quotes around the json object, my second is how do I fix it. I'm so close to it all working.

I am returning a jsonp response from two different approaches. The first is by using jaxb annotation objects, this works well. (see callback1)
The second is by wrapping/chaining another external rest service into a string and returning the reponse as below using Client, this doesn't work (callback2). I think my problem is in the string and the jaxb object queryResult's String result property.

@GET @Path("test")
@Produces({"application/javascript","application/json"})
public JSONWithPadding getQueryResult(@QueryParam("callback") String callback, @QueryParam("param1") double param1 ... etc)
{
...
Client client = Client.create();
WebResource wr = client.resource(sb.toString()); //sb is a rest service url

String stringResponse = wr.get(String.class);
QueryResult = new QueryResult();
queryResult.setResult(stringResponse); // seems fine {}, not "{}"

return new JSONWithPadding(new GenericEntity<QueryResult>(queryResult){}, callback);
}


....
the responses are
callback1({"correctResult":{"location":"xxx,"status":"false"}) // no extra quote before json object/location, this was built using jaxb object, not a string returned as above in getqueryresult
callback2({"queryResult":"{\"displayFieldName\" //see extra quote before {\, so String representation of property result's json not valid... my client could be coded to be ok with this, but it's wrong..
...
//pseudo example
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "queryResult", propOrder = {"result"})
@XmlRootElement(name="queryresult")
public class QueryResult {

    @XmlElement(required = true,name="result")
    protected String result; // i think this the problem beastie, the string being added is ok but when jersey makes this a callback json element it adds it with extra quotes. Is my client.resource to blame? what would solve the double quote issue?

    /**
     * Gets the value of the result property.
     *
     * @return
     * possible object is
     * {_at_link String }
     *
     */
    public String getResult() {
        return result;
    }

    /**
     * Sets the value of the result property.
     *
     * @param value
     * allowed object is
     * {_at_link String }
     *
     */
    public void setResult(String value) {
        System.out.println(value);
        this.result = value;
        
    }

}





_________________________________________________________________
Share your photos with Windows Live Photos – Free.
http://clk.atdmt.com/UKM/go/134665338/direct/01/