java - Springframework 无法读取 http 帖子
问题描述
我的前端正在发布一个json
对象:
[{"FUND_CODE":"testFUND","PORTF_CODE":"testcode","CLIENT_STAT":null,"CLIENT_LOCAL_CURR":null,"CLIENT_START_DT":"2017-04-06","CLIENT_END_DT":"9998-12-31","CREATED_USER_ID":"testuser","CREATED_DATETIME":"2017-05-04","LAST_UPDATE_USER":null,"LAST_UPDATE_DT":null}]
控制器在上面发布json
使用:
deleteTableData = (schema: string, tableName: string, records: string[]): Observable<number> => {
if (records.length > 0){
const headers = new HttpHeaders({
'Content-Type': 'application/json'
});
try {
return this._http.post<number>(this.moduleUrl + '/delete?schemaName=' + schema + "&tableName=" + tableName, records, { headers: headers });
} catch (err) {
console.log(err);
}
}
}
我的后端收到这样的:
@CrossOrigin
@RequestMapping(value = "/delete", method = RequestMethod.POST)
public ResponseEntity<RestWrapper> delete(@RequestParam String schemaName, @RequestParam String tableName, @RequestBody Json body){
StringBuilder resStr = new StringBuilder();
log.info("POST REQUEST RECEIVED ==> " + schemaName + " && " + tableName + " && " + body.value());
return new ResponseEntity<>(new RestWrapper(resStr.toString()), HttpStatus.OK);
}
我得到的错误:
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of springfox.documentation.spring.web.json.Json out of START_ARRAY token
如何解决此错误?
编辑
忘了提一个重要的要求:我不能在服务器上创建特定的数据模型。有多个表要更新,表的列表会逐渐增加。因此,我需要一个通用 API 来执行操作。
解决方案
当我将 HTTP 正文数据类型从更改Json
为JsonNode
JsonNode和ObjectNode之间的Jackson JSON区别
如果我错了,请纠正我,我的理解是,由于我没有为传入的 JSON 定义明确的模型,我将不得不使用 JsonNode 这是一个抽象类。
如果有人知道更多,请告诉我。
推荐阅读
- python - 执行 try 块时出现缩进错误
- git - 从 Github 中删除未跟踪的文件
- file - Slack - 如何通过 API 上传具有非片段模式的文件
- tensorflow - tensorflow deeplabv3+ 类权重
- sql - SQL0338N 将两个功能查询放在一起时出错
- php - 将 PHP 注册脚本从 Sha1 转换为 Bcrypt
- python - Python 2.7 脚本在调试模式下使用断点,但在运行时不使用
- hadoop - 从 hdfs 到 GreenPlum 的 Sqoop 导出不起作用
- android - 从本地主机流式传输视频
- ios - 如何按照与另一个实体的关系顺序从 CoreData 获取实体