为了账号安全,请及时绑定邮箱和手机立即绑定

无法反序列化 Wiremock Json 文件配置中收到的 START_ARRAY 令牌异常中的

无法反序列化 Wiremock Json 文件配置中收到的 START_ARRAY 令牌异常中的

烙印99 2023-08-16 17:55:56
WireMock我正在尝试使用带有文件配置的独立 jar来模拟一些 API JSON。下面是JSON包含我正在使用的多个存根映射的文件-{  "mappings": [{      "request": {        "method": "GET",        "url": "/users"      },      "response": {        "status": 200,        "body": [{            "id": 1,            "name": "Leanne Graham",            "username": "Bret",            "email": "Sincere@april.biz",            "address": {              "street": "Kulas Light",              "suite": "Apt. 556",              "city": "Gwenborough",              "zipcode": "92998-3874",              "geo": {                "lat": "-37.3159",                "lng": "81.1496"              }            },            "phone": "1-770-736-8031 x56442",            "website": "hildegard.org",            "company": {              "name": "Romaguera-Crona",              "catchPhrase": "Multi-layered client-server neural-net",              "bs": "harness real-time e-markets"            }          },          {            "id": 2,            "name": "Ervin Howell",            "username": "Antonette",            "email": "Shanna@melissa.tv",            "address": {              "street": "Victor Plains",              "suite": "Suite 879",              "city": "Wisokyburgh",              "zipcode": "90566-7771",              "geo": {                "lat": "-43.9509",                "lng": "-34.4618"              }            },            "phone": "010-692-6593 x09125",            "website": "anastasia.net",            "company": {              "name": "Deckow-Crist",              "catchPhrase": "Proactive didactic contingency",              "bs": "synergize scalable supply-chains"            }          }        ],        "headers": {          "Content-Type": "application/json"        }      }    },    {      "request": {        "method": "GET",        "url": "/posts?userId=1"      },      "response": {        "status": 200,        "body": "[]"      }    }当我尝试Wiremock使用独立 jar ( wiremock-standalone-2.24.1.jar) 启动服务器时,出现以下异常,我验证了 Json 架构,它看起来没问题。
查看完整描述

3 回答

?
偶然的你

TA贡献1841条经验 获得超3个赞

响应定义中的正文可以是bodyjsonBody,base64Bodynull


查看完整回答
反对 回复 2023-08-16
?
至尊宝的传说

TA贡献1789条经验 获得超10个赞

body参数始终需要 WireMock 中的字符串。一旦我将我的响应作为字符串传递到正文中,它就起作用了。



查看完整回答
反对 回复 2023-08-16
?
智慧大石

TA贡献1946条经验 获得超3个赞

对象“ response ”中的键“ body ”仅接受字符串。如果您想向其传递 JSON,可以将键“ body ”替换为键“ jsonBody ”。



查看完整回答
反对 回复 2023-08-16
  • 3 回答
  • 0 关注
  • 103 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信