from my local Django Rest Framework service I get the following JSON output:
{
"count": 5,
"next": null,
"previous": null,
"results": [
{
"id": 1,
"created": "2020-04-18T16:00:16.060915Z",
"name": "Germany",
"groups": [
{
"id": 1,
"created": "2020-04-18T16:03:11.138661Z",
"name": "MyGroup1",
"owner_id": 1
},
{
"id": 2,
"created": "2020-04-18T16:03:20.701660Z",
"name": "MyGroup2",
"owner_id": 1
},
...
Each Country
can have many Group
s. For this I have created the following data classes in my Android App project:
@JsonClass(generateAdapter = true)
data class NetworkCountryContainer(
val count: Long,
val next: String?,
val previous: String?,
val results: List<Country>
)
@Entity(tableName = "country_table")
@JsonClass(generateAdapter = true)
data class Country(
@PrimaryKey
@Json(name="id")
val countryId : Int,
@Json(name="name")
val countryName: String,
@Json(name="groups")
val groupList: List<Group> // <--- this field causes the ERROR
)
@Entity(tableName = "group_table")
@JsonClass(generateAdapter = true)
data class Group(
@PrimaryKey
@Json(name="id")
val groupId : Int,
@Json(name="name")
val groupName: String,
@Json(name="owner_id")
val ownerId: Int
)
Android Studio tells me this:
Cannot figure out how to save this field into database. You can consider adding a type converter for it.
Why I need a TypeConverter ? And how can I build one ?