将JSON解析为DTO时出现问题。
JSON响应是:
{
"content": [
{
"id": 350,
"reg": "FA-2001",
"Email": "abc@gmail.in",
"Mobile": "+9192000000",
"Name": "dr kumar",
"Ip": "0:0:0:0:0:0:0:1",
"Datetime": "2022-10-20T13:50:49",
}
],
"pageable": {
"sort": {
"unsorted": false,
"sorted": true,
"empty": false
},
"pageNumber": 0,
"pageSize": 20,
"offset": 0,
"paged": true,
"unpaged": false
},
"last": true,
"totalPages": 1,
"totalElements": 1,
"first": true,
"sort": {
"unsorted": false,
"sorted": true,
"empty": false
},
"numberOfElements": 1,
"size": 20,
"number": 0,
"empty": false
}
DTO
@Data
public class OtherResponse {
@JsonProperty(value = "content")
private Map content;
}
获取
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type java.util.LinkedHashMap<java.lang.Object,java.lang.Object> from Array value (token JsonToken.START_ARRAY)
请建议如何在Map或其他对象中获取值我的主要关注点是发送特定的键值对作为响应。
1条答案
按热度按时间mqxuamgl1#
在你的json String中,
content
是一个List。你可以做的是相应地更新OtherResponse
:或者甚至为它定义一个专用类:
PS:更新了答案,增加了Pageable字段。我在这里使用的是从
org.springframework.data.domain.Pageable
导入的Pageable接口