2016-11-18 15 views
0

私はREST Assuredを使用してPOST呼び出しからレスポンスを保存しています。私はJSON形式のファイルにレスポンスを保存したいのですが、次にPUT呼び出しを行うためにボディが必要になります。現在、私はファイルへの応答を格納することができますが、String形式で格納します。どうすれば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(); 
     } 

    } 

} 

答えて

0

私はRESTが提供するprettyPrint()機能を使用してそれを行うことができたが

アシュアード
関連する問題