spring - org.springframework.http.converter.HttpMessageNotReadableException:JSON 解析错误
问题描述
我有来自第 3 方的回复,如下所示
[
{
"url": "https://abc/10",
"created": "2021-02-26 10:45:14",
"status": "approved",
"ref": "12452",
"brand": "edr",
"reason": "jkjkj"
},
{
"url": "https://bvc/20",
"created": "2021-02-26 10:43:18",
"status": "rejected",
"ref": "14562",
"brand": "yghj",
"reason": "asd",
}
]
我们有一堂课。
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class GetDetails {
private List<Detail> details = new ArrayList<>();
// getters, setters and toString()
}
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class Detail {
@JsonProperty(value = "url")
private String url;
@JsonProperty(value = "created")
private Instant created;
@JsonProperty(value = "status")
private String status;
@JsonProperty(value = "ref")
private String ref;
@JsonProperty(value = "brand")
private String brand;
@JsonProperty(value = "reason")
private String reason;
//Getters, Setters and toString()
}
但是在转换时我们遇到了错误
错误 com.openbet.commons.sdk.common.util.RequestSenderImpl - HTTP 交换期间出现意外异常:org.springframework.http.converter.HttpMessageNotReadableException:JSON 解析错误:无法反序列
com.document.GetDetails
化 START_ARRAY 令牌的实例;嵌套异常是 com.fasterxml.jackson.databind.exc.MismatchedInputException:无法反序列com.document.GetDetails
化 START_ARRAY 标记的实例
有人可以建议我在这里做错了什么吗?
解决方案
public ResponseEntity<?> getDetails(@RequestBody List<Detail> details){}
您的案例的方法签名示例。
json 中没有 details 属性
您正在尝试转换下面的示例,因此您无法转换它
{
details : [
{
"url": "https://abc/10",
"created": "2021-02-26 10:45:14",
"status": "approved",
"ref": "12452",
"brand": "edr",
"reason": "jkjkj"
},
{
"url": "https://bvc/20",
"created": "2021-02-26 10:43:18",
"status": "rejected",
"ref": "14562",
"brand": "yghj",
"reason": "asd",
}
]
}
推荐阅读
- machine-learning - 时间序列模型 - 设备/客户明智
- c# - 在类属性中设置自定义列名以导出到文件
- javascript - 如何将 Formik Field 渲染为 textarea + styled-components?
- mysql - 如何在node.js所有应用程序文件中使用mysql?
- service-worker - 从 Service Worker 获取重定向 API 调用
- c# - 如何在 Powershell 中使用 C# 接口和扩展方法?
- java - 当我向既是“管理员”又是“用户”的用户提供令牌时出现未经授权的错误
- python - Django for 循环仅通过查询集循环一次
- css - 将当前线性梯度移动到元素顶部
- c - 在 C 项目中列出“从不链接”源文件