Json List to String List:Spring mvc Controller

时间:2023-01-28 18:02:44

I want to send this List example :

我想发送这个List示例:

{"id":[1]}

To this controller :

到这个控制器:

public String addUsersToProject(@RequestBody List<String> usersIds, @PathVariable String projectTitle){..}

But I can't read the list :

但我无法阅读清单:

Could not read document: Can not deserialize instance of java.util.ArrayList

Any suggestion will be appreciated, Thank you.

任何建议将不胜感激,谢谢。

1 个解决方案

#1


0  

The easiest way is create wrapper class with id field as List (userIds).

最简单的方法是创建包含类,其id字段为List(userIds)。

Example:

class IdsWrapper {
    private List<Integer> id;
}

And use it in controller:

并在控制器中使用它:

public String addUsersToProject(@RequestBody IdsWrapper ids) {...}

Also you can check link Possible maping solutions

您也可以查看链接可能的maping解决方案

#1


0  

The easiest way is create wrapper class with id field as List (userIds).

最简单的方法是创建包含类,其id字段为List(userIds)。

Example:

class IdsWrapper {
    private List<Integer> id;
}

And use it in controller:

并在控制器中使用它:

public String addUsersToProject(@RequestBody IdsWrapper ids) {...}

Also you can check link Possible maping solutions

您也可以查看链接可能的maping解决方案