0
I am trying to consume an api, but it is not returning an internal list, it only returns totalSize and done.
Code:
public List<PessoaResponseDTO> get(String url) throws Exception {
List<PessoaResponseDTO> list = new ArrayList<>();
try {
url = "api.com/query/?q=select+id+,+name+,+CPF__C+from+individual";
String accessToken = new TokenUtil().recuperaToken();
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", "Bearer "+accessToken);
ResponseEntity<PessoaResponseDTO> entity = new RestTemplate().exchange(
url, HttpMethod.GET, new HttpEntity<Object>(headers),
PessoaResponseDTO.class);
list = Arrays.asList(entity.getBody());
} catch (HttpClientErrorException clientError) {
loggerError.error(clientError.getMessage());
} catch (Exception e) {
loggerError.error(e.getMessage());
}
return list;
}
classe PessoaResponseDTO
@SerializedName("totalSize")
private String totalSize;
@SerializedName("done")
private Boolean done;
@SerializedName("records")
private List<ListaPessoasDTO> records = null;
public PessoaResponseDTO() {}
Someone could help, they’ve been through it?
Hey, Alan, what’s up? You can format your code in single-spaced font in Stackoverflow involving it with 3 bass accents (```) before and after the code. This will make it easier for people to read your code and help you. If it is not clear, take a look here.
System.out.println("O seu código vai ficar tipo assim!");
– Allan Juan
thanks for the tip
– Alan Dantas
Have you already consumed this api by some program (like Postman) to confirm if this is the return of itself?
– Bruno
Bruno, I was able to solve by writing down @Jsonproperty
– Alan Dantas