无法从START_OBJECT令牌中反序列化int []实例 [英] Cannot deserialize instance of int[] out of START_OBJECT token

查看:208
本文介绍了无法从START_OBJECT令牌中反序列化int []实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想将int和String数组作为RequestBody发送: 这是json:

Hello guys I want to send Array of int and String as RequestBody: This is the 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"

"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"

我尝试使用Array代替此int [],但是我遇到了相同的错误...

I have tried with Array instead this int[] but I have got same error...

推荐答案

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

Create an object instead of int[], String to hold them,

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

并将控制器方法更改为

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

这篇关于无法从START_OBJECT令牌中反序列化int []实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆