您好我到处寻找答案,但我找不到答案。我需要获取一个Object列表。在我必须将这些对象传递给Rest API之前,代码将生成此对象列表。
这是我的方法:
public static List<Cashflow> generateCashflow(Credit credit) {
RestTemplate restTemplate = new RestTemplate();
String url = "http://localhost:9080/example/";
...
}
这是我的最后一次尝试:
ResponseEntity<? extends ArrayList<Cashflow>> responseEntity = restTemplate.postForEntity(url, darlehen, (Class<? extends ArrayList<Cashflow>>)ArrayList.class);
ArrayList<Cashflow> cashflowList = responseEntity.getBody();
System.out.println(cashflowList.get(0).getCashflow());
return cashflowList;
}
这是我的Rest API控制器:
@RestController
public class CashflowGenerator {
@RequestMapping(value = "/example", method = RequestMethod.POST)
@ResponseBody
public List<Cashflow> genCashflow(@RequestBody Credit credit) {
List<Cashflow> cashflowList = new ArrayList<Cashflow>();
// Some Math Stuff
cashflowList.add(cashflow);
return cashflowList;
}
这是我的Cashflown
课程:
@JsonIgnoreProperties(ignoreUnknown = true)
public class Cashflow {
private Date date;
private double cashflow;
public Cashflow() {
super();
}
在IBM web sphere服务器上运行此作为maven构建时,我收到了以下消息:
java.lang.ClassCastException:无法强制转换java.util.LinkedHashMap de.example.Cashflow