无法使用 jackson objectmapper 读取响应。退出 START_OBJECT 令牌。这是输入的 json 和错误消息。PaymentResponse java pojo 是通用代码,我无权添加任何注释。添加反序列化配置有什么帮助吗?ObjectMapper objectMapper = new ObjectMapper();PaymentResponse[] paymentResponse = objectMapper.readValue(serverResponseStr, PaymentResponse[].class);{ "PaymentResponse[]": [ { "uid": "111", "name": "kiran" }, { "uid": "112", "name": "kumar" } ]}Can not deserialize instance of PaymentResponse[] out of START_OBJECT tokencom.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of PaymentResponse[] out of START_OBJECT token at [Source: {"PaymentResponse[]": [{"uid": "111","name": "kiran"},{"uid": "112","name": "kumar"}]}
1 回答
UYOU
TA贡献1878条经验 获得超4个赞
理想的情况是,如果您可以将响应更改为以下内容:
[{
"uid": "111",
"name": "kiran"
}, {
"uid": "112",
"name": "kumar"
}
]
如果您无法更改它,请尝试以下操作:
ObjectMapper objectMapper = new ObjectMapper();
TypeFactory typeFactory = objectMapper.getTypeFactory();
JsonNode array = objectMapper.readValue(anotherResponseStr, JsonNode.class);
JsonNode paymentResponse = array.get("PaymentResponse[]");
List<PaymentResponse> p = objectMapper.readValue(paymentResponse.toString(),
typeFactory.constructCollectionType(List.class, PaymentResponse.class));
添加回答
举报
0/150
提交
取消