【发布时间】:2019-03-13 02:14:41
【问题描述】:
我有一个 Detail 对象,它具有 Product 类型的对象属性。产品有一个名为 xxx 的属性,它是一个数组列表。我使用邮递员对 URL 进行 GET,结果如下所示:
"Product": {
"id": "2",
"xxx": [
"price": "50"
},
{
"price": "60"
}
]
}
这个结果很好。但是,在我的 Spring 项目中,当我将 RestTemplate 用作:
restTemplate.getForEntity("someurl", Detail.class).getBody();
当 xxx 列表包含 2 个或更多元素时,我得到正确的结果。 但是,当此列表中只有元素时,出现错误:
org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
How do I fix this issue that I am facing with my call to restTemplate.getForEntity as above?
【问题讨论】:
-
您的 JSON 不正确,看起来像是在发布前手动编辑的。
-
你能提供未编辑的 + JSON 失败吗?
标签: java spring jackson resttemplate