I have a cloud endpoint function that returns a json string as response. An api endpoint makes an http request to the cloud function. How can I return the json string response as it is. I tried the following(just as an example)
@ApiMethod(
name = "json",
httpMethod = ApiMethod.HttpMethod.GET
)
public JsonObject json()
{
String item = "{\"name\":\"Josh\",\"sex\":\"male\"}";
JsonParser jsonParser = new JsonParser();
return jsonParser.parse(item).getAsJsonObject();
}
and I get the following message
WARNING: exception occurred while invoking backend method
[INFO] GCLOUD: java.io.IOException: com.fasterxml.jackson.databind.JsonMappingException: JsonObject (through reference chain: endpoints.repackaged.com.google.gson.JsonObject["asInt"]
Caused by: java.lang.UnsupportedOperationException: JsonObject
I understand JSONObject is not part of the supported returned type, I just want to know how I can just output the json string response from the endpoint just as it is