无法将json反序列化到列表集合中。我用的是lombok,它包含字段变量:
@Data
@Builder
@EqualsAndHashCode(exclude = "success")
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class AparsersResponceDto {
private Integer success;
private ArrayList<String> data;
}
重新分配了向api发布请求的控制器:
public ValidatableResponse getFirstAparserStatus(AparsersDto toGetAparser) {
return RestAssured
.given().spec(getDefaultRequestSpecification())
.body(toGetAparser)
.when()
.post(apars141 + port1)
.then()
.log().all();
}
并提取post请求的正文:
private AparsersController aparsersController = new AparsersController();
public AparsersResponceDto postFirstBody(AparsersDto aparsersDto) {
return aparsersController
.getFirstAparserStatus(aparsersDto) //Sent post request with the body aparsersDto through RestAssured
.statusCode(200)
.extract().body().as(AparsersResponceDto.class); // Here i can't make extract of the 'data' field due to collection List.
}
响应json:
"success": 1,
"data": {
"45.90.34.87:59219": [
"http"
],
"144.76.108.82:41049": [
"http"
],
"5.9.72.48:59473": [
"http"
],
"130.0.232.208:49327": [
"http"
],
"217.172.179.54:39492": [
"http"
],
...
complite错误消息:
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.ArrayList<java.lang.Object>` out of START_OBJECT token at [Source: (StringReader); line: 1, column: 21] (through reference chain: com.rest.dto.AparsersResponceDto["data"])
我该怎么修?
1条答案
按热度按时间jk9hmnmh1#
data
在json中不是ArrayList<String>
相反,它是一个Map<String,List<String>>
所以把你的数据改成如下。