In an api I have to send a JSonArray
within a JSonObject
. The JSonObject
is this:
{
"token" : "1",
"task_name" : "Name",
"task_desc" : "Description",
"task_start_date" : "2020/10/01",
"task_end_date" : "2020/10/02",
"task_award" : "15",
"child_ids" : [
{
"child_id" : "1"
},
{
"child_id" : "2"
}
]
}
When I send this request with Postman, it works fine and the response is receiving in a way I want. But when implementing it in android app, I get an error which says:
retrofit2.adapter.rxjava2.httpexception http 500 internal server error
So it is obvious it's not a server-side bug because it works fine in Postman.
Here is the interface that I use for my api:
interface CreateTaskRemote {
@FormUrlEncoded
@POST("parent_create_task")
fun createTask(
@Field("token") parentToken: String,
@Field("task_name") title: String,
@Field("task_desc") description: String,
@Field("task_start_date") startDate: String,
@Field("task_end_date") endDate: String,
@Field("task_award") award: String,
@Field("child_ids") childIds: List<ChildId> <-- here i'm sending array
): Single<BooleanResponse>
}
And the ChildId
class:
data class ChildId(
@SerializedName("child_id") val id: Int
)
It seems there is a bug with implementing JSON Array. But I searched a lot on the internet and I couldn't find a solution which works for my situation.