Consumption WS Rest returns null

1

I'm consuming a WS to get vehicle data, the API that was passed to me returns a JSON:

{
"success": true,
"message": "",
"result": [  {
        "Codigo": "1013",
        "Placa": "ABC1234",
        "Ano": 2016,
        "Uf": "SP",
        "Marca": "Marca1",
        "Modelo": "OF-1418"
    }, {
        "Codigo": "1015",
        "Placa": "ABC1244",
        "Ano": 2016,
        "Uf": "SP",
        "Marca": "Marca1",
        "Modelo": "OF-1418"
    }, {
        "Codigo": "100",
        "Placa": "KYX2244",
        "Ano": 2013,
        "Uf": "SP",
        "Marca": "Mbb",
        "Modelo": "OF-1313"
    }
  ]
}

I am using restTemplate of Spring and to turn JSON into object I have analyzed JSON and created three classes:

@JsonIgnoreProperties(ignoreUnknown = true)
public class Result {

   private String codigo;
   private String placa;    
   private Integer ano; 
   private String uf;   
   private String marca;    
   private String modelo;   


@JsonIgnoreProperties(ignoreUnknown = true)
public class RestResponse {

   private Boolean success;
   private String message;
   private Result[] result;


public class Response {

   @JsonProperty
   private RestResponse RestResponse;

And to consume in my service class I did it this way:

    Response response = restTemplate.getForObject(url, Response.class);

    System.out.println("Retorno: " + response.toString());

Only return is null.

Where am I going wrong?

Code Update

I deleted the Response class, I only got two classes in the RestResponse and Result now I realize that something has already changed so I'm calling it

RestResponse response = restTemplate.getForObject(url, RestResponse.class);

When looking at the response object, the attribute success and message now has content but the Result [] result attribute I check for it

Result[] array = response.getResult();
System.out.println("Tamanho do array: " + array.length);

and the array has size more than itero over it the attributes are null.

    
asked by anonymous 29.12.2018 / 16:44

1 answer

1

I made two changes the first I implemented Serializable and according to the JSON the key / value pair the key it starts with Capital so I inserted @JsonProperty for each attribute @JsonProperty ("Code") private String code; @JsonProperty ("Card") private String; .......

    
30.12.2018 / 15:53