【发布时间】:2022-01-10 06:19:53
【问题描述】:
我正在开发具有以下代码的服务(我可以更改此代码):
import com.google.gson.JsonObject;
import com.google.gson.Gson;
Gson gson = new Gson();
JsonObject json = new JsonObject();
json.addProperty("customer", gson.toJson(customer));
anotherServiceClient.dispatch(json.toString());
AnotherService 类代码有一个 dispatch 方法实现,它接受一个 String 对象并将其添加到一个 JSON 中,其中 party 是一个 String。我无法更改此代码。
JsonObject json = new JsonObject();
json.addProperty("party", inputCustomerJson);
我需要 anotherService 的输出如下:
"party": "{\"customer\":\"{\"id\":\"A123\"}"}
但它是:
"party": "{\"customer\":\"{\\\"id\\\":\\\"A123\\\"}"}
【问题讨论】: