Eric Ampire [MOD]
09/03/2021, 2:17 PMUser
I can retrieved Users using two different end-points,
The first one return recent
users and the second one return popular
users, for both popular and recent end-points the data returning by the API has the same structure except one thing
The recent end-point return a json like this, that differ from the popular end-point at the recent field
{
"data": {
"recent": { ... } // Here the difference
}
}
And the popular end-point return a json like this, that differ from the recent end-point at the popular field
{
"data": {
"popular": { ... } // Here the different
}
}
Here the class hierarchy
@Serializable
data class ApiResponse(
@SerialName("data")
val apiData: Data
)
@Serializable
data class Data(
@SerialName("recent") // My problem is here
val page: Page
)
@Serializable
data class Page(
val currentPage: Int,
val from: Int,
val perPage: Int,
val results: List<User>,
)
For the Data
class, there is a way to customize the behavior of the SerialName
annotation to deal both with recent and popular name as the Page
class has the same structure for recent and popular end-point without having to duplicate stuff ??ms
09/03/2021, 2:26 PMData
data class and make them both default to nullms
09/03/2021, 2:27 PMJavier
09/03/2021, 2:27 PMEric Ampire [MOD]
09/03/2021, 2:28 PMJavier
09/03/2021, 2:29 PMEric Ampire [MOD]
09/03/2021, 2:35 PM