3

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 Groups. 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 ?

ebeninki
  • 909
  • 1
  • 12
  • 34
  • Does this answer your question? [Android room persistent library - TypeConverter error of error: Cannot figure out how to save field to database"](https://stackoverflow.com/questions/44582397/android-room-persistent-library-typeconverter-error-of-error-cannot-figure-ou) – ADM Apr 19 '20 at 12:44
  • no it didnt help, I need it in kotlin – ebeninki Apr 19 '20 at 15:38

0 Answers0