大家好我想发送一个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 []但我有同样的错误......
创建一个对象而不是int[], String
来保存它们,
public class Example {
private int[] customUiModel;
private String user;
}
并将控制器方法更改为,
public CustomUiModel createCustomUiObject(@RequestBody @Valid Example exe) {}