org.springframework.http.converter.HttpMessageNotReadableException: JSON 解析错误
org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error
我收到了如下第 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",
}
]
我们有 class.
@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()
}
但是在转换时我们遇到了以下错误
ERROR com.openbet.commons.sdk.common.util.RequestSenderImpl - Unexpected exception during HTTP exchange:
org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of com.document.GetDetails
out of START_ARRAY token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of com.document.GetDetails
out of START_ARRAY token
有人可以告诉我我在这里做错了什么吗?
public ResponseEntity<?> getDetails(@RequestBody List<Detail> details){}
您案例的方法签名示例。
json
中没有详细信息属性
您正在尝试转换下面的示例,因此您无法转换它
{
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",
}
]
}
我收到了如下第 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",
}
]
我们有 class.
@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()
}
但是在转换时我们遇到了以下错误
ERROR com.openbet.commons.sdk.common.util.RequestSenderImpl - Unexpected exception during HTTP exchange: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of
com.document.GetDetails
out of START_ARRAY token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance ofcom.document.GetDetails
out of START_ARRAY token
有人可以告诉我我在这里做错了什么吗?
public ResponseEntity<?> getDetails(@RequestBody List<Detail> details){}
您案例的方法签名示例。
json
中没有详细信息属性您正在尝试转换下面的示例,因此您无法转换它
{
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",
}
]
}