0
我存储了使用REST Assured进行的POST调用的响应。我想将响应以JSON格式存储在文件中,因为我将需要旁边的主体进行PUT调用。目前我能够存储对文件的响应,但它以字符串格式存储。我怎样才能将其转换为JSON格式?如何将RESTAssured输出存储为JSON格式的文件
@Test
public void postIt() throws Exception {
if(Ver>=currentVer) {
InputStream resource = getClass().getClassLoader().getResourceAsStream("inputJSONBody.json");
String json = IOUtils.toString(resource);
System.out.println(json);
Response response = given().contentType("application/json").accept("application/json").body(json).when().post("/APIURI");
String responseBody = response.getBody().asString();
response.then().statusCode(201);
try {
FileWriter file = new FileWriter("./output.json");
file.write(responseBody);
file.flush();
file.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}