gpt4 book ai didi

java - 无法从 START_OBJECT token 中反序列化 int[] 实例

转载 作者:行者123 更新时间:2023-11-30 02:02:55 26 4
gpt4 key购买 nike

大家好,我想将 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 parse error: Cannot deserialize instance ofint[]out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance ofint[]out of START_OBJECT token\n at [Source: (PushbackInputStream); line: 1, column: 1]", "path": "/custom/save"

我尝试用数组代替这个 int[] 但我遇到了同样的错误...

最佳答案

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

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

并将 Controller 方法更改为,

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

关于java - 无法从 START_OBJECT token 中反序列化 int[] 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52222578/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com