The request body you posted doesn't match the class PersonRequest
.
Change the request body structure to:
{
"name": "blablabla",
"phone": "+1 11111111",
"birthday": "2000-01-01"
}
UPDATE:
Since you can't update the request structure, your other option is to change the class structure by creating two classes as below:
class PersonRequest(var fields: List<Field>)
class Field(var id: String, var value:Any)
UPDATE 2:
The last step, which is optional based on your requirement, is that you can manipulate the PersonRequest
class now and convert it to any other class using normal setters/getters.
UPDATE 3:
To convert the List<Field>
to PersonRequest
, you could do it like this:
val personRequest = PersonRequest()
fields.forEach {
when(it.id) {
"name" -> personRequest.name = it.value
"phone" -> personRequest.phone = it.value
"birthday" -> personRequest.birthday = it.value
}
}
Not the neatest of codes, but...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…