Oussema Aroua Oussema Aroua - 6 months ago 32
Android Question

How to send an list to API using retrofit2

I developed an API using

EVE
.

This is the schema:

central_schema = {
'name': {
'type': 'string',
'required': True,
},
'id_account': {
'type': 'list',
}
}


I'm trying to send a list using
retrofit 2
. I tried the API using
POSTMAN
. Everytime I got this response:

id account "must be of list type"


I used many types of requests (
PATCH
,
POST
,
PUT
), but I still get the same error.

Answer

You can create Model class like below:

public class Model{
    public String name;
    public List<String> id_account;
}

And use it in retrofit 2.

It will produce below json:

{
    "name": "xyz",
    "id_account" : [
         "1",
         "2"
    ]
}