Solve the JSON list parameter format error of the Post request: JSON parse error: Cannot deserialize value of type `java.util.ArrayList<x>

Problem Description

When debugging the interface today, I encountered a problem. There is a json body parameter of post request,

insert image description here

Then there are only two attributes in vo, id and a collection.

insert image description here

Then when using apifox to debug the interface, it is found that the json parsing is abnormal:

操作失败,JSON parse error: Cannot deserialize value of type `java.util.ArrayList<org.jeecg.file.entity.SysConfigFile>` from Object value (token `JsonToken.START_OBJECT`);

insert image description here

Through the prompt information, it can be found that the parsing is not possible because the json structure is incorrect.

error demonstration

I originally passed it like this, and it will report an error:

{
  "id": "403",
  "x": {
    "serialVersionUID": 1,
    "id": 1,
    "fileCode": "demoData",
    "fileName": "demoData",
    "fileNum": 1,
    "fileSize": "demoData",
    "fileCategoryDic": 1,
    "fileTypeDic": 1,
    "allowType": "demoData",
    "izRequired": 1,
    "fileDesc": "demoData",
    "templateUrl": "demoData",
    "handleUrl": "demoData",
    "delFlag": 1,
    "createBy": "demoData",
    "createTime": "2023-05-09 09:45:36",
    "updateBy": "demoData",
    "updateTime": "2023-05-09 09:45:36",
    "remark": "demoData",
    "tenantId": "demoData",
    "flag": true,
    "quyang": "demoData"
  }
}

Demonstrate correctly

A layer of array should be added to the list so that it can be parsed normally

{
  "id": "403",
  "sysConfigFiles": [{
    "serialVersionUID": 1,
    "id": 1,
    "fileCode": "demoData",
    "fileName": "demoData",
    "fileNum": 1,
    "fileSize": "demoData",
    "fileCategoryDic": 1,
    "fileTypeDic": 1,
    "allowType": "demoData",
    "izRequired": 1,
    "fileDesc": "demoData",
    "templateUrl": "demoData",
    "handleUrl": "demoData",
    "delFlag": 1,
    "createBy": "demoData",
    "createTime": "2023-05-09 09:45:36",
    "updateBy": "demoData",
    "updateTime": "2023-05-09 09:45:36",
    "remark": "demoData",
    "tenantId": "demoData",
    "flag": true,
    "quyang": "demoData"
  }]
}

extension, multiple collection elements

If there are multiple collections, you can use them directly and divide them, for example:

{
  "id": "403",
  "sysConfigFiles": [{
    "serialVersionUID": 1,
    "id": 1,
    "fileCode": "demoData",
    "fileName": "demoData",
    "fileNum": 1,
    "fileSize": "demoData",
    "fileCategoryDic": 1,
    "fileTypeDic": 1,
    "allowType": "demoData",
    "izRequired": 1,
    "fileDesc": "demoData",
    "templateUrl": "demoData",
    "handleUrl": "demoData",
    "delFlag": 1,
    "createBy": "demoData",
    "createTime": "2023-05-09 09:45:36",
    "updateBy": "demoData",
    "updateTime": "2023-05-09 09:45:36",
    "remark": "demoData",
    "tenantId": "demoData",
    "flag": true,
    "quyang": "demoData"
  },{
    "serialVersionUID": 1,
    "id": 1,
    "fileCode": "demoData",
    "fileName": "demoData",
    "fileNum": 1,
    "fileSize": "demoData",
    "fileCategoryDic": 1,
    "fileTypeDic": 1,
    "allowType": "demoData",
    "izRequired": 1,
    "fileDesc": "demoData",
    "templateUrl": "demoData",
    "handleUrl": "demoData",
    "delFlag": 1,
    "createBy": "demoData",
    "createTime": "2023-05-09 09:45:36",
    "updateBy": "demoData",
    "updateTime": "2023-05-09 09:45:36",
    "remark": "demoData",
    "tenantId": "demoData",
    "flag": true,
    "quyang": "demoData"
  }
  ]
}

Guess you like

Origin blog.csdn.net/weixin_46713508/article/details/130574995