Olá Estou desenvolvendo um .jar que consulta o valor de cotação do dollar, através da requisição para um endpoint disponibilizado pelo banco central. Quando faço a requisição via postman o json vem corretamente, mas pelo java usando o restTemplate ocorre o seguinte erro:
java.lang.NoSuchMethodError: org.springframework.util.MimeType.<init>(Lorg/springframework/util/MimeType;)V
at org.springframework.http.MediaType.<init>(MediaType.java:511) ~[spring-web-5.3.3.jar:5.3.3]
at org.springframework.http.MediaType.parseMediaType(MediaType.java:623) ~[spring-web-5.3.3.jar:5.3.3]
at org.springframework.http.HttpHeaders.getContentType(HttpHeaders.java:967) ~[spring-web-5.3.3.jar:5.3.3]
at org.springframework.web.client.HttpMessageConverterExtractor.getContentType(HttpMessageConverterExtractor.java:136) ~[spring-web-5.3.3.jar:5.3.3]
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:93) ~[spring-web-5.3.3.jar:5.3.3]
Classe service
@Override
public Map<String,Object> consultaCotacao() {
boolean ok = false;
Gson g = new Gson();
Map<String, Object> response = new HashMap();
String filter = setFiltroRequisicao();
HttpHeaders header = new HttpHeaders();
header.set("Content-Type", MediaType.APPLICATION_JSON_VALUE);
RestTemplate restTemplate = new RestTemplate();
HttpEntity<String> request = new HttpEntity<>(header);
ParameterizedTypeReference<CotacaoMoeda> typeRef = new ParameterizedTypeReference<CotacaoMoeda>() {
};
String endpoint = ConstantsURL.CONSULTA_COTACAO_COMPRA + filter;
try{
ResponseEntity<CotacaoMoeda> responseEntity = restTemplate.exchange(endpoint,
HttpMethod.GET, request, typeRef);
CotacaoMoeda cotacaoMoeda = responseEntity.getBody();
response.put("cotacaoMoeda",cotacaoMoeda);
response.put("HttpStatus", responseEntity.getStatusCode());
}catch(Exception e){
response.put("cotacaoMoeda",null);
response.put("HttpStatus", 500);
e.printStackTrace();
}
Classe CotaçãoMoeda
@Data
public class CotacaoMoeda {
@JsonDeserialize(contentAs = Value.class)
private Value value;
}
Classe Value
@Data
public class Value {
private BigDecimal cotacaoCompra;
}
Json retorno
{
"@odata.context": "https://was-p.bcnet.bcb.gov.br/olinda/servico/PTAX/versao/v1/odata$metadata#_CotacaoDolarDia(cotacaoCompra)",
"value": [
{
"cotacaoCompra": 5.36200
}
]
}
Obs: Já tentei colocar no retorno do restTemplate como List , mas não deu certo. Tbm tentei colocar na classe CotacaoMoeda o atributo value como list, mas também não foi