Hire QA – Specialized in QA Recruitment, Technical Interviews and Testing Solutions

Creating JSON Object Request Body Using Java Map

Category: Rest Assured

We can create a JSON Object using a Map in Java. You must note here that I am using the word “JSON Object”. A JSON Object is a key-value pair and can be easily created using a Java Map. A Map in Java also represents a collection of key-value pairs.

{
“username” : “Phani”,
“lastname” : “Nagula”
}

Map mapPayload = new HashMap();
mapPayload .put("username", "Phani");
mapPayload .put("lastname", "Nagula");

                   RestAssured
		   .given()
			  .baseUri("https://hireqa.co.in/register")
			  .contentType(ContentType.JSON)
			  .body(mapPayload )
			  .log()
			  .all()
		// WHEN
		   .when()
			   .post()
		// THEN
		   .then()
			   .assertThat()
			   .statusCode(200)
			   .log()
			   .all();

Leave a Reply

Your email address will not be published. Required fields are marked *