Problems for the development of the POJO with Rest Assured

Asked

Viewed 49 times

0

Hello, I’m training with Rest Assured, I can’t show the project itself, but basically, it’s past token and some parameters per header, and the API returns various data, it would be something like :

{
   "data": {
         "data_nascimento" : "exemplo",
         "nome_completo" : "exemplo",
         "numero_cpf" : "exemplo",
         "vivo" : true
    }
}

The class I created as follows:

public Class Data {

 private String data_nascimento;
 private String nome_completo;
 private String numero_cpf;
 private boolean vivo;

 //Getter e Setter

}

And in the call I’m trying in two different ways, but both return null value

Data dados = given()
               .header(//map com header e token)
             when.
               .get("/cliente").as(Data.class);

That was one of the ways the other was to use extract().body().as(Data.class), but the data are not being deserialized.

  • I managed to solve, I created a separate class and called this class.

1 answer

0


I managed to make the following call:

 public class DadosPessoa{

@JsonProperty("data_nascimento")
private String data_nascimento;

@JsonProperty("nome_completo")
 private String nome_completo;

@JsonProperty("numero_cpf")
 private String numero_cpf;

@JsonProperty("vivo")
 private boolean vivo; 

//getter e setter

And in another class I called her as follows:

public class Data{

@JsonProperty("data")
private DadosPessoa dados;

public DadosPessoa getDados(){
return dados;
}

//toString

from there when I make the call just take the "getDados(). getNome_completo();" for example

I had to read some posts to understand where I was going wrong, but it worked here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.