Search code examples
javaoutputtestngrest-assured

JSON data is displayed in one line in output console of Intellij rest assured


When I convert JSON body to String via response.getBody().asString() it looses line breakers in JSON response. How can I keep them and display in console output?

If I use simple GET request to get some JSON data, it has beautified view

import io.restassured.RestAssured;
import io.restassured.http.Method;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
import org.testng.annotations.Test;

public class Demo6_GET_AuthTest
{
    @Test
    public void AuthTest()
    {
       RestAssured.baseURI = "https://test.sideways6.com/api/";
       RequestSpecification httprequest = RestAssured.given();
       Response response = httprequest.request(Method.POST, "auth/login");

       String responseBody = response.getBody().asString();
       System.out.println(responseBody);
    }
}

sample of output


Solution

  • Printing asString will not beautify response,

    Try System.out.println(response.then().log().all());