Moatez Bouhdid Moatez Bouhdid - 1 year ago 123
HTTP Question

Json List to String List : Spring mvc Controller

I want to send this List example :


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 Source

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


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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download