Имея json,
{
"owner": {
"name": "frank",
"address": "some street",
"city": "a city"
},
"employees": [
{
"name": "todd",
"address": "some street2",
"city": "a city2",
"title": "manager"
},
{
"name": "micheal",
"address": "some street3",
"city": "a city3",
"title": "engineer"
}
],
"partner": {
"name": "ford",
"address": "some street a",
"city": "Magdeburg",
"employees": [
{
"name": "marina",
"address": "some street2",
"city": "a city2",
"title": "sectary"
}
]
}
}
с помощью инструмента POJO, чтобы получить модель данных для десериализации в классы, и посмотрите, как минимум,
"name", "address", "city"
распространены в json objects.
вопрос: как сделать общее выражение Person (val name: String, val address: String, val city: String) для использования в модели данных для десериализации Gson?
@ApiSerializable
@Parcelize
data class Owner(
@SerializedName("name")
val name: String? = null,
@SerializedName("address")
val address: String? = null,
@SerializedName("city")
val city: String? = null
) : Parcelable
@ApiSerializable
@Parcelize
data class Employee(
@SerializedName("name")
val name: String? = null,
@SerializedName("address")
val address: String? = null,
@SerializedName("city")
val city: String? = null,
@SerializedName("title")
val title: String? = null
) : Parcelable
@ApiSerializable
@Parcelize
data class employees(
@SerializedName("employees")
val employees: List<Employee>? = null
) : Parcelable
@ApiSerializable
@Parcelize
data class Partner(
@SerializedName("name")
val name: String? = null,
@SerializedName("address")
val address: String? = null,
@SerializedName("city")
val city: String? = null,
@SerializedName("employees")
val employees: List<Employee>? = null
) : Parcelable