1

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

1
  • Why do you want to do this? Commented Aug 28, 2017 at 21:52

1 Answer 1

1

What you can do is to wrap your JSON into a String (in your endpoint) and return the wrapper object. You wrapper object could be a simple POJO with only one String attribute. Then on your API consumer side, you just read the string (representing your JSON) and use it as you wish.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.