无法从START_OBJECT标记中反序列化int []的实例

问题描述 投票:1回答:1

大家好我想发送一个int的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标记反序列化实例ofint [];嵌套异常是com.fasterxml.jackson.databind.exc.MismatchedInputException:无法在[来源]的START_OBJECT标记中反序列化实例ofint [] :(PushbackInputStream); line:1,column:1]“,”path“:”/ custom / save“

我试过使用Array而不是这个int []但我有同样的错误......

java arrays json spring-boot
1个回答
1
投票

创建一个对象而不是int[], String来保存它们,

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

并将控制器方法更改为,

public CustomUiModel createCustomUiObject(@RequestBody @Valid Example exe) {}
© www.soinside.com 2019 - 2024. All rights reserved.