Moatez Bouhdid Moatez Bouhdid - 1 month ago 11
HTTP Question

Json List to String List : Spring mvc Controller

I want to send this List example :

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

Answer

The easiest way is create wrapper class with id field as 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

Comments