本文介绍了无法从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);
}

这是错误:

我尝试使用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 []实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-26 16:30
查看更多