How to post array in retrofit android-ThrowExceptions

Exception or error:

How can I post following parameter in retrofit through post method ?

 "params":{"body": {
    "learning_objective_uuids": [
    "note": "FasfAFSASFASDF",
    "user_uuids": [
} }
How to solve:
   void functionName(
        @FieldMap Map<String, String> learning_objective_uuids, @FieldMap Map<String, String> user_uuids, @Field("note") String note,
        Callback<CallBackClass> callback

Better solution : Use arraylist.. Reference link : johnsonsu

       void functionName(
            @Field("learning_objective_uuids[]") ArrayList<String> learning_objective_uuids, @Field("user_uuids[]") ArrayList<String> user_uuids, @Field("note") String note,
            Callback<CallBackClass> callback


see this example where i need to pass registration fields data as json request

Call<RegisterEntity> customerRegistration(@Body JsonObject registrationData);

here i have created registrationData is

private static JsonObject generateRegistrationRequest() {
        JSONObject jsonObject = new JSONObject();
        try {
            JSONObject subJsonObject = new JSONObject();
            subJsonObject.put("email", "");
            subJsonObject.put("firstname", "abc");
            subJsonObject.put("lastname", "xyz");

            jsonObject.put("customer", subJsonObject);
            jsonObject.put("password", "password");

        } catch (JSONException e) {
        JsonParser jsonParser = new JsonParser();
        JsonObject gsonObject = (JsonObject) jsonParser.parse(jsonObject.toString());
        return gsonObject;


As of today, running the Retrofit implementation 'com.squareup.retrofit2:retrofit:2.1.0'

This works perfectly…

Call<Reply> updateManyItem(@Header("Authorization") String auth_token, @Field("items[]") List<Integer> items, @Field("method") String method);

You can disregard the @Header and @Field("method") …. the main piece is @Field("items[]") List<Integer> items

This is what allows you to send the items. On the API side I am simply looking for an array of integers and this works perfectly.


Go to this site : JSON Schema 2 POJO

Paste your example Json format and then

Select source type : JSON , annotation style : None

Create a POJO class then , for example your class name : MyPOJOClass

Then in your Api :

public Call<Void> postArray(@Body MyPOJOClass mypojoclass);

If you have headers too you can add them in parameters like that :

@Header("Accept") String accept,@Header("Content-Type") String contentType

@Edit : for your comment checkout my answer : how-to-use-gson-2-0-on-onresponse-from-retrofit-2-0


if you want to send a list of the same name the only thing that worked for me in retrofit2 is to use @Query

   void functionName(
        @Query("category") List<Int> categories

this will send it like:

the accepted answers seem not to work in Retrofit2


I’ve found a new workaround:

you can send it as a String:

Call<SomeResponse> postSomething(@Field("ids")String ids);

and send pass it like this:

Call<SomeResponse> call = service.postSomething("0","0", Arrays.toString(new int[]{53551, 53554}));

Best Regards!

Leave a Reply

Your email address will not be published. Required fields are marked *