如何使用嵌套值发送JsonObject作为REST保证的Post请求

use*_*212 8 http-post rest-assured jsonobject

我放心使用 - https://code.google.com/p/rest-assured/wiki/Usage 我的JsonObject看起来像这样

{
"id": "12",
"employeeInfo": null,
"employerInfo": null,
"checkDate": 1395093997218,
"netAmount": {
"amount": 70,
"currency": "USD"
},
"moneyDistributionLineItems": [
{
"mAmount": 100,
"employeeBankAccountId": "BankAccount 1"
}
],
}
Run Code Online (Sandbox Code Playgroud)

如何使用REST保证的POST将其作为参数的一部分发送?我试过了

given().param("key1", "value1").param("key2", "value2").when().post("/somewhere").then().
        body(containsString("OK")); 
Run Code Online (Sandbox Code Playgroud)

但对于具有嵌套值的HUGE对象,这是不可扩展的.有更好的方法吗?

Joh*_*han 8

您只需在正文中发送JSON文档.例如,如果你在名为myJson的String中有你的JSON文档,那么你可以这样做:

String myJson = ..
given().contentType(JSON).body(myJson).when().post("/somewhere"). .. 
Run Code Online (Sandbox Code Playgroud)

您还可以使用POJO,输入流和byte []而不是String.