问题描述
今天在调试接口的时候,遇到一个问题。有一个post请求的json body参数,
然后vo里面只有两个属性,id和一个集合。
然后使用apifox调试接口的时候,发现json解析异常:
操作失败,JSON parse error: Cannot deserialize value of type `java.util.ArrayList<org.jeecg.file.entity.SysConfigFile>` 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加一层数组,这样就能正常解析文章来源:https://www.toymoban.com/news/detail-506647.html
{
"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"
}]
}
扩展,多个集合元素
如果有多个集合,那么直接使用,分割即可,例如:文章来源地址https://www.toymoban.com/news/detail-506647.html
{
"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"
}
]
}
到了这里,关于解决Post请求JSON列表参数格式报错:JSON parse error: Cannot deserialize value of type `java.util.ArrayList<x>的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!