Question d’entretien chez Moolya Software Testing

Send the below Nested JSON object as a POST request payload ``` { "author": { "lastname": "Doe", "firstname": "Jane" } } ``` Keep in mind: 1. Not to use it as hardcoded in the body method 2. Do Not refer to it as a string 3. Not to use as a file object

Réponse à la question d'entretien

Utilisateur anonyme

16 mars 2023

import com.fasterxml.jackson.databind.ObjectMapper; import java.util.HashMap; import java.util.Map; // Create a HashMap to represent the JSON object Map jsonMap = new HashMap<>(); Map authorMap = new HashMap<>(); authorMap.put("lastname", "Doe"); authorMap.put("firstname", "Jane"); jsonMap.put("author", authorMap); // Convert the HashMap to JSON using Jackson ObjectMapper objectMapper = new ObjectMapper(); String jsonPayload = objectMapper.writeValueAsString(jsonMap); // Use the JSON payload in the RestAssured POST request given() .contentType("application/json") .body(jsonPayload) .when() .post("/your-endpoint") .then() .statusCode(200);