0

I'm testing API with Rest Assured, I have all the necessary dependencies, all setup, the only question is, I have created all POJO classes for Request Body, I'm in the phase, where I have to verify, whether all the data in request body created successfully, in order to do that, I have to create again POGO classes for Response Body, I'm confused how to do that, I mean I know how to create POJO classes, but mine is not working, please help me to do it in a right way.

These are my POJO classes, the Request body is working fine, but the Response is not working

@Data

public class ProductRequest {

private List<ProductCustomerTypes> productCustomerTypes;

private String address;

private City city;

private double latitude;

private List<ProductPrices> productPrices;

private boolean active;

private List<ProductTypes> productTypes;

private List<ProductVideos> productVideos;

private String shortDescription;

private String cityId;

private String fullDescription;

private boolean mostPopular;

private String productTypeId;

private String createdAt;

private List<ProductRegions> productRegions;

private String calendarColor;

private List<ProductExcludedTags> productExcludedTags;

private String name;

private List<ProductIncludedTags> productIncludedTags;

private List<ProductWorkingDates> productWorkingDates;

private double longitude;

private List<ProductTags> productTags;



import java.util.List;
@Getter
@Setter


public  class ProductResponse {

private List<ProductRequest> productRequestCashed;

 private List<ProductCustomerTypes> productCustomerTypesCashed;


 private City city;

 private double latitude;

 private List<ProductPrices> productPrices;

 private boolean active;

 private List<ProductTypes> productTypesCashed;

 private List<ProductVideos> productVideos;

 private String shortDescription;

 private String cityId;

 private String fullDescription;

 private boolean mostPopular;

 private String productTypeId;

 private String createdAt;

 private List<ProductRegions> productRegions;

 private String calendarColor;

 private List<ProductExcludedTags> productExcludedTags;

 private String name;

 private List<ProductIncludedTags> productIncludedTags;

 private List<ProductWorkingDatesResponse> productWorkingDatesCashed;

 private double longitude;

 private List<ProductTags> productTags;
}
1
  • 2
    Hi, first off all please apply proper formatting to your code snippets. Then please add more details regarding what exactly is going wrong. How you're deserializing response and what are error messages if any of what's the observed behavior.
    – Alexey R.
    Jun 3 at 14:05
0
package extendreport_2;


import com.google.gson.Gson;


import io.restassured.RestAssured;


public class printsomething {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        class test {
            private String name;

            private String[] job;

            private String[] id;

            private String[] createdAt;
        }

        String maxJson = RestAssured
                .given().header("Content-type", "application/json").and().body("{\r\n"
                        + "         \"name\": \"morpheus\",\r\n" + "            \"job\": \"leader\"\r\n" + "        }")
                .post("https://reqres.in/api/users").thenReturn().asString();

        Gson gson = new Gson();
        Student max = gson.fromJson(maxJson, Student.class);

        System.out.println(gson.toJson(max));

    }

    public class Student {
        private String name;
        private String job;
        private int id;
        private String createdAt;
    }

}

Just see if the data type defined for your response class is correct , else it will return null

1
0
ProductResponse response = when().get("your-endpoint").then().extract().as(ProductResponse.class);

Something like above would work. Not sure about this, but if RestAssured uses Jackson to map response to the beans, then you may need to add empty(default) constructors to your POJOS/POGOS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.