我有一个返回JSON的Web服务。我正在尝试使用此Web服务spring mvc打印屏幕。我写的代码是400错误。我该如何解决?
我用json对象:
{"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}]}
控制器:
@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";
}
谢谢...
问题是目标类不能是非静态内部类。它不能嵌入在我认为是问题的Controller类中。
详细信息在here中,但归结为Java添加内部类的方式意味着他们没有Jackson所需的默认构造函数。
或检查您的类CurrencyRates是否具有没有任何参数的构造函数。