org.springframework.http.converter.httpMessageNoteableException:json解析错误

z8dt9xmd  于 2021-07-16  发布在  Java
关注(0)|答案(1)|浏览(315)

我有一个第三方的回应如下

[
    {
        "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()

}

但在转换过程中,我们得到了以下错误
error com.openbet.commons.sdk.common.util.requestsenderimpl-http交换期间出现意外异常:org.springframework.http.converter.httpMessageNotradableException:json分析错误:无法反序列化的示例 com.document.GetDetails 启动外\u数组令牌;嵌套异常为com.fasterxml.jackson.databind.exc.missmatchdinputException:无法反序列化的示例 com.document.GetDetails 启动外\u数组令牌
有人能告诉我我做错了什么吗?

js5cn81o

js5cn81o1#

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",
    }
  ]
}

相关问题