为了账号安全,请及时绑定邮箱和手机立即绑定

无法从 START_OBJECT 令牌反序列化 int[] 的实例

无法从 START_OBJECT 令牌反序列化 int[] 的实例

慕沐林林 2021-09-03 17:35:40
大家好,我想将 int 和 String 数组作为 RequestBody 发送:这是 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);}这是错误:"message": "JSON 解析错误:无法反序列化 START_OBJECT 令牌中的 int[] 实例;嵌套异常是 com.fasterxml.jackson.databind.exc.MismatchedInputException:无法反序列化 START_OBJECT 令牌中的 int[] 实例\n 在 [Source] :(PushbackInputStream); line: 1, column: 1]", "path": "/custom/save"我试过用 Array 而不是这个 int[] 但我有同样的错误......
查看完整描述

1 回答

?
开心每一天1111

TA贡献1836条经验 获得超13个赞

创建一个对象而不是int[], String持有它们,


public class Example {

    private int[] customUiModel;

    private String user;

}

并将控制器方法更改为,


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


查看完整回答
反对 回复 2021-09-03
  • 1 回答
  • 0 关注
  • 183 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信