代码之家  ›  专栏  ›  技术社区  ›  xmlParser

无法从START\u对象标记中反序列化int[]的实例

  •  1
  • xmlParser  · 技术社区  · 7 年前

    这是json:

    {
        "customUiModel": [1, 3, 5],
        "user": "user"
    }
    

    这是端点代码:

    @RequestMapping(value = "/save", method = RequestMethod.POST)
          @ResponseStatus(HttpStatus.CREATED)
         public CustomUiModel createCustomUiObject(@RequestBody @Valid int[] customUiModel, String user) {
    
        return customAppService.saveCustom(customUiModel, user);
    }
    

    这就是错误:

    启动\对象标记;嵌套异常为 com.fasterxml.jackson公司.databind.exc.missmatchdinputException不匹配:无法 在[源: (PushbackInputStream);行:1,列:1],“path”:“/自定义/保存”

    我尝试用数组代替int[],但是我得到了相同的错误。。。

    1 回复  |  直到 7 年前
        1
  •  3
  •   benjamin c    7 年前

    创建对象而不是 int[], String

    public class Example {
        private int[] customUiModel;
        private String user;
    }
    

    并将控制器方法更改为,

    public CustomUiModel createCustomUiObject(@RequestBody @Valid Example exe) {}