Hello everyone, I have a class hierarchy like the following, and I have an API that return a list of
User
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 ??