我想在服务类中返回一个 JSON 文字@GraphQLQuery(name = "renderUI", description = "Schema for your form")public String renderUI() { String genratedSchema = "{" + " \"schema\": {" + " \"type\": \"object\"," + " \"id\": \"urn:jsonschema:profile:model:DemoForm\"," + " \"properties\": {" + " \"comment\": {" + " \"type\": \"string\"," + " \"title\": \"Comment\"" + " }" + " }" + " }," + " \"form\": [" + " {" + " \"key\": \"comment\"," + " \"type\": \"textarea\"," + " \"required\": false," + " \"description\": \"Add your Comment here\"," + " \"placeholder\": \"fill your comment please\"" + " }" + " ]" + "}"; return genratedSchema;}上面的代码转义了响应中的所有引号{ "data": { "renderUI": "{ \"schema\": { \"type\": \"object\", \"id\": \"urn:jsonschema:com:fnstr:bankprofile:gppbankprofile:model:DemoForm\", \"properties\": { \"comment\": { \"type\": \"string\", \"title\": \"Comment\" } } }, \"form\": [ { \"key\": \"comment\", \"type\": \"textarea\", \"required\": false, \"description\": \"Add your Comment here\", \"placeholder\": \"fill your comment please\" } ]}" }}如何删除转义字符?
1 回答
慕码人8056858
TA贡献1803条经验 获得超6个赞
GraphQL 响应已经是 JSON,因此显然需要对其中的任何字符串进行适当的转义。如果要向其中添加动态对象,则必须实际返回一个对象,而不是字符串。对象可以是任何具有正确结构的对象,可以是 a Map、Jackson's ObjectNode、Gson'sJsonObject或 POJO。
例如
@GraphQLQuery(name = "renderUI", description = "Schema for your form")
public Map<String, Object> renderUI() {
Map<String, Object> dynamic = new HashMap<>();
dynamic.put("schema", ...); //fill the whole structure
return dynamic;
}
或者
@GraphQLQuery(name = "renderUI", description = "Schema for your form")
public ObjectNode renderUI() {
return ...;
}
添加回答
举报
0/150
提交
取消