Home > Enterprise >  How to post nested array object with kotlin using retrofit
How to post nested array object with kotlin using retrofit

Time:06-08

I'm trying to use post method in retrofit but confused how to implement it

How can I implement a retrofit using the post method?

{
    "companyId": "id8921",
    "employee": [
        {
            "id": "em128",
            "age": 38
        },
        {
            "id": "emp292",
            "age": 44
        },
        {
            "id": "emp321",
            "amount": 3
        }
    ]
}

CodePudding user response:

This how to post array object as form-url_encoded just use this in retrofit

@POST("api_url")
@FormUrlEncoded
Call<MasterResponse<JobCardSaveResponse>> jobCardSave(@FieldMap Map<String, Object> _jobCardRequest,
                                                      @Field("qty[]") List<String> qty,
                                                      @Field("service_id[]") List<String> service_id);

CodePudding user response:

use RequestBody data class :

data class RequestBody(
    val companyId: String,
    val employee: List<Employee>
)

data class Employee(
    val age: Int,
    val amount: Int,
    val id: String
)
  • Related