Мне удалось сопоставить ответ JSON с объектом пользователя.
User.java
/**
*
*/
package com.apiautomation.framework.titan.models;
/**
* @author vamsir
*
*/
public class User {
public String name;
public String color;
public String pantone_value;
public int year;
public int id;
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the color
*/
public String getColor() {
return color;
}
/**
* @param color the color to set
*/
public void setColor(String color) {
this.color = color;
}
/**
* @return the pantone_value
*/
public String getPantone_value() {
return pantone_value;
}
/**
* @param pantone_value the pantone_value to set
*/
public void setPantone_value(String pantone_value) {
this.pantone_value = pantone_value;
}
/**
* @return the year
*/
public int getYear() {
return year;
}
/**
* @param year the year to set
*/
public void setYear(int year) {
this.year = year;
}
/**
* @return the id
*/
public int getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(int id) {
this.id = id;
}
}
ResReqClassMapping.java
/**
*
*/
package com.apiautomation.framework.titan.testsuites.samples;
import org.testng.annotations.Test;
import com.apiautomation.framework.titan.models.User;
import io.restassured.RestAssured;
/**
* @author vamsir
*
*/
public class ResReqClassMapping {
@Test
public void testUserSerialisation() {
User user = RestAssured.given()
.when()
.get("https://reqres.in/api/unknown/2")
.then()
.extract()
.response()
.getBody()
.jsonPath()
.getObject("data", User.class);
System.out.print(user.getColor());
}
}
Ответ
[RemoteTestNG] detected TestNG version 6.14.3
#C74375
PASSED: testUserSerialisation
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================