How to send a JsonObject with nested values ​​as a send request in REST

I take confidence - https://code.google.com/p/rest-assured/wiki/Usage My JsonObject looks like this:

{ "id": "12", "employeeInfo": null, "employerInfo": null, "checkDate": 1395093997218, "netAmount": { "amount": 70, "currency": "USD" }, "moneyDistributionLineItems": [ { "mAmount": 100, "employeeBankAccountId": "BankAccount 1" } ], } 

How can I send this as part of the parameters using an RST-guaranteed POST? I tried

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

but it does not scale for HUGE objects with nested values. Is there a better approach?

+8
jsonobject rest-assured
source share
2 answers

You just send the JSON document in the body. For example, if you have your JSON document in a String called myJson, you can simply do the following:

 String myJson = .. given().contentType(JSON).body(myJson).when().post("/somewhere"). .. 

You can also use POJO, input stream and byte [] instead of string.

+8
source share
  URL file = Resources.getResource("PublishFlag_False_Req.json"); String myJson = Resources.toString(file, Charsets.UTF_8); Response responsedata = given().header("Authorization", AuthorizationValue) .header("X-App-Client-Id", XappClintIDvalue) .contentType("application/vnd.api+json") .body(myJson) .with() .when() .post(dataPostUrl); 
+2
source share

All Articles