首页 > 解决方案 > 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 来执行操作。

标签: javajsonspringangular

解决方案


当我将 HTTP 正文数据类型从更改JsonJsonNode

JsonNode和ObjectNode之间的Jackson JSON区别

如果我错了,请纠正我,我的理解是,由于我没有为传入的 JSON 定义明确的模型,我将不得不使用 JsonNode 这是一个抽象类。

如果有人知道更多,请告诉我。


推荐阅读