【发布时间】:2018-02-04 12:57:53
【问题描述】:
我有一个云端点函数,它返回一个 json 字符串作为响应。 api 端点向云函数发出 http 请求。如何按原样返回 json 字符串响应。我尝试了以下(仅作为示例)
@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 字符串响应,就像它一样
【问题讨论】:
-
你为什么要这样做?
标签: java json google-app-engine google-cloud-endpoints