如何使用rest-assured传递多级数据的请求体

How to pass the request body with multi level data using rest-assured

正在尝试通过以下方式使用放心发送带有多级数据的请求体。

请求正文:

{
  "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");

}

按上述方式发送时,收到错误请求。

如何在上面的代码中传递这种数据

你不需要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));