java - Spring Cloud Contract 无法转换 contract.yml 中的 unicode 字符串
问题描述
我想要来自 YAML 编写的合同文件的 WireMock 存根的 JSON 文件。
但是 Spring Cloud Contract Gradle Plugin 在包含 unicode 字符串(例如“日本”)时无法正确转换合约文件。
(我通过执行 Gradle 插件的“generateClientStubs”任务来生成存根。)
具体来说,我制作了以下合约 yaml 文件。
name: get-all-users
request:
url: /users
method: GET
response:
status: 200
headers:
content-type: application/json; charset=UTF-8
body:
-
id: 001
name: alice
country: US
-
id: 002
name: bob
country: 日本
在完成 generateClientStubs 任务后,我得到了以下 JSON 文件。
{
"id" : "b776c7d1-fd6d-454a-be92-ef02b8eec793",
"request" : {
"url" : "/users",
"method" : "GET"
},
"response" : {
"status" : 200,
"body" : "[{\"id\":1,\"name\":\"alice\",\"country\":\"US\"},{\"id\":2,\"name\":\"bob\",\"country\":\"\\u65e5\\u672c\"}]",
"headers" : {
"content-type" : "application/json; charset=UTF-8"
},
"transformers" : [ "response-template" ]
},
"uuid" : "b776c7d1-fd6d-454a-be92-ef02b8eec793"
}
如您所见,响应正文的 unicode 字符串(尤其是 "country\":\"\u65e5\u672c\" 部分)未正确转换。我想要的是如下:
"body" : "[{\"id\":1,\"name\":\"alice\",\"country\":\"US\"},{\"id\":2,\"name\":\"bob\",\"country\":\"日本"}]"
我必须处理这样的日语字符串(因为我是日本人......)。
我该如何解决它们?
感谢您的阅读。
解决方案
推荐阅读
- pic - PIC24F 读取模拟交流麦克风值时出现问题
- angular-material - 您可以在垫子表格列的标题中添加垫子工具提示吗?
- java - org.apache.commons.lang.time.DateUtils vs org.apache.commons.lang3.time.DateUtils;
- regex - 具有两个不同分隔符的正则表达式提取
- java - 在java中的静态方法中访问全局变量
- python - Python Config 组和选择
- python - Python 将 JSON 标准化为 DataFrame
- javascript - 这个关键字问题?
- kubernetes - k8s升级集群时的pod状态
- c# - Blazor WASM Button Onclick 每次都不会触发