遇到错误
Could not write JSON: java.util.LinkedHashMap cannot be cast to java.lang.String; nested exception is com.fasterxml.jackson.databind.JsonMappingException: java.util.LinkedHashMap cannot be cast to java.lang.String (through reference chain: com.mediamath.octane.royaloak.model.Bank["ids"]->java.util.ArrayList[0])
@Builder
@Value
public class Bank {
private List<String> ids;
}
public void addId(List<String> ids) {
HttpEntity<Bank> request = new HttpEntity<>(Bank.builder().ids(ids).build(), headers);
ResponseEntity<Bank> response = restTemplate.postForEntity(testUrl, request, Bank.class);
}
这是来自Wiremock
public void mockResponse(int statusCode) {
JsonObject body = factory.createObjectBuilder()
.add("ids", factory.createArrayBuilder()
.add("testId")
.add("testId2")
.add("testId3")
.build())
.build();
stubFor(post(urlPathMatching("/testUrl"))
.willReturn(aResponse()
.withStatus(statusCode)
.withHeader("Content-Type", "application/json")
.withBody(body.toString())));
}
我遇到了上面显示的异常,我相信这与杰克逊的炮击有关。我创建和反序列化响应是否错误?