-1
Well, I’m doing a Spring project along with Spring-cloud-openFeign for integration with a Fipe api to access car values. See the class:
@Service
@FeignClient(name = "FipeService", url = "https://parallelum.com.br/fipe/api/v1")
public interface FipeService {
@GetMapping("/{type}/marcas")
public List<FipeResponse> getBrands(@PathVariable String type);
@GetMapping("/{type}/marcas/{brandCode}/modelos")
public List<FipeResponse> getModels(@PathVariable String type, @PathVariable String brandCode);
@GetMapping("/{type}/marcas/{brandCode}/modelos/{modelCode}/anos")
public List<FipeResponse> getYears(@PathVariable String type, @PathVariable String brandCode, @PathVariable String modelCode);
@GetMapping("/{type}/marcas/{brandCode}/modelos/{modelCode}/anos/{year}")
public FipeResponse getPrice(@PathVariable String type, @PathVariable String brandCode, @PathVariable String modelCode, @PathVariable String year);
}
Fiperesponse is a class of mine used by Jackson to insert the return of the api into it, which he does in the method getBrands()
because the Json answer is simple, an array only with name and code. See the class:
public class FipeResponse {
private String nome;
private String codigo;
private String valor;
public FipeResponse(String nome, String codigo, String valor) {
this.nome = nome;
this.codigo = codigo;
this.valor = valor;
}
public FipeResponse(){
}
getters e setters
}
However, in the second endpoint I have a problem, the getModels
returns an array of models and years (test the link: https://parallelum.com.br/fipe/api/v1/carros/marcas/59/modelos) and Jackson can not insert in Fiperesponse obviously, but, I tried inside Fiperesponse to add two other classes as composition, one for models and the other for years, both with name and attribute code only, and I inserted in Fiperesponse so:
public class FipeResponse {
private String nome;
private String codigo;
private String valor;
private List<FipeAnos> anos;
private List<FipeModelos> modelos;
public FipeResponse(String nome, String codigo, String valor, List<FipeAnos> anos, List<FipeModelos> modelos) {
this.nome = nome;
this.codigo = codigo;
this.valor = valor;
this.anos = anos;
this.modelos = modelos;
}
public FipeResponse(){
}
getters e setters
}
And yet Jackson still can’t enter the data using endpoint getModels()
, but works normally using getBrands()
, I can access the attributes and everything. What I did wrong?
I don’t understand the downvote on the question... If further details are required just ask, now give -1 and not say anything does not solve at all.
– Kevin Ricci