问题描述
今天在调试接口的时候,遇到一个问题。有一个post请求的json body参数,
然后vo里面只有两个属性,id和一个集合。
然后使用apifox调试接口的时候,发现json解析异常:
操作失败,JSON parse error: Cannot deserialize value of type `java.util.ArrayList` from Object value (token `JsonToken.START_OBJECT`);
通过提示信息,可以发现是因为json结构不对导致解析不了。
错误示范
我原来是这样传的,会报错:
{ "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" }}
正确示范
应该给list加一层数组,这样就能正常解析
{ "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" }]}
扩展,多个集合元素
如果有多个集合,那么直接使用,分割即可,例如:
{ "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" } ]}
来源地址:https://blog.csdn.net/weixin_46713508/article/details/130574995