且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Json Mapping Exception无法反序列化START_ARRAY令牌中的实例

更新时间:2021-07-29 22:54:29

您已将参数声明为单个对象,但您将其作为多个对象的数组返回在您的JSON文档中。

You have declared parameters as a single object, but you are returning it as an array of multiple objects in your JSON document.

您的模型当前将参数节点定义为 ParametersType 对象:

Your model currently defines the parameters node as a ParametersType object:

@JsonProperty( "parameters" )
@XmlElement( required = true )
protected ParametersType parameters;

这意味着您的模型对象需要一个如下所示的JSON文档:

This means your model object is expecting a JSON document that looks like the following:

{
    "templateId": "123",
    "parameters": {
            "parameter": [
                {
                    "key": "id",
                    "value": "1",
                    "type": "STRING_TYPE"
                },
                {
                    "key": "id2",
                    "value": "12",
                    "type": "STRING_TYPE"
                }
            ]
        },
    "documentFormat": "PDF"
}

但在你的JSON文档返回一个 ParametersType 对象的数组。因此,您需要将模型更改为ParametersType对象列表:

But in your JSON document you are returning an array of ParametersType objects. So you need to change your model to be a list of ParametersType objects:

@JsonProperty( "parameters" )
@XmlElement( required = true )
protected List<ParametersType> parameters;

您返回一个ParametersType对象数组的事实是解析器抱怨无法使用的原因从START_ARRAY反序列化对象。它正在寻找具有单个对象的节点,但在JSON中找到了一个对象数组。

The fact that you are returning an array of ParametersType objects is why the parser is complaining about not being able to deserialize an object out of START_ARRAY. It was looking for a node with a single object, but found an array of objects in your JSON.