尝试使用以下方式使用rest-guarantee发送具有多级数据的请求正文。
请求正文:
{
"phoneNumber":1217071016,
"details":
[
{
"id":"123",
"name":"New",
"email":"hello@gmail.com"
},
{
"id":"234",
"name":"next",
"email":"next@gmail.com"
}
]
}
@Test public void generateToken(){
Map<String,String> userDetails = new HashMap<>(); userDetails.put("phoneNumber", "1217071016"); userDetails.put("details.Id", "241342"); userDetails.put("details.name", "New Name"); userDetails.put("details.email", "eclipse@test.com"); Response response = given() .contentType("application/json") .queryParam("access_token", "LL6rX8LRP7") .body(userDetails) .post("http://site/rest/try/update");
}
以上述方式发送时,收到错误请求。
如何在上面的代码中传递这种数据
答案 0 :(得分:0)
您不需要Map<String, String>
而是Map<String, Object>
:
Map<String, Object> userDetails = new HashMap<>();
Map<String, Object> details = new HashMap<>();
details.put("id", "241342");
details.put("name", "New Name");
details.put("email", "eclipse@test.com");
userDetails.put("phoneNumber", "1217071016");
userDetails.put("details", Arrays.asList(details, details));