I have a web service that returns JSON. I am trying to print the screen using this web service spring mvc. The code I wrote is getting 400 errors. How can I resolve it?
I use json object:
{"currencyRates":[{"currencyPair":"BGN/IRR","date":1519922870105,"askPrice":4.376,"bidPrice":2.162},{"currencyPair":"ROL/LKR","date":1519922870105,"askPrice":4.056,"bidPrice":2.132},{"currencyPair":"KES/MGF","date":1519922870105,"askPrice":4.067,"bidPrice":3.005}]}
Controller:
@RequestMapping(value = "/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public String userList(ModelMap model) {
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<List<CurrencyRate>> rateResponse = restTemplate.exchange(
"http://localhost:8080/denemeDenemeDeneme/rates", HttpMethod.GET, null,
new ParameterizedTypeReference<List<CurrencyRate>>() {
});
List<CurrencyRate> rates = rateResponse.getBody();
model.addAttribute("list", rates);
return "list";
}
Thanks...
The problem is that the target class which cannot be a non-static inner class. It doesn't work embedded in the Controller class which I think is the problem.
The details are in here but it boils down to the way Java added inner classes means they don't have the default constructor that Jackson requires.
or Check if your class CurrencyRates does have constructor without any parameter.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments