0
我有一個雲終端函數,返回一個json字符串作爲響應。 api端點向雲端功能發出http請求。我該如何返回json字符串響應。我嘗試以下(就像一個例子)用java應用引擎返回JSONObject
@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();
}
,我得到以下信息
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
我理解的JSONObject是不支持的返回類型的一部分,我只是想知道我怎麼能只需從端點輸出json字符串響應就像它是
你爲什麼想這樣做? – saiyr