您好,我想将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解析错误:无法反序列化int [] out实例 START_OBJECT令牌;嵌套异常为 com.fasterxml.jackson.databind.exc.MismatchedInputException:无法 在[_Source]的START_OBJECT令牌\ n中反序列化int []实例 (PushbackInputStream);行:1,列:1]“,”路径“:” / custom / save“
我尝试使用Array代替此int [],但我遇到了同样的错误...
答案 0 :(得分:1)
创建一个对象而不是int[], String
来容纳它们,
public class Example {
private int[] customUiModel;
private String user;
}
并将控制器方法更改为
public CustomUiModel createCustomUiObject(@RequestBody @Valid Example exe) {}