'Room field / getter mismatch warning when using sealed classes or Any

I have a Room (v2.4.0-beta01) database, and whilst it works fine, during the build it gives a field vs getter mismatch warning on a few fields, included below.

I suspect this is due to an interop issue between Kotlin and Java, since the field definitions in the Kotlin and autogenerated Java don't perfectly match. Whilst the Any causing problems is understandable, I'd have expected the list of sealed class objects to work smoothly.

Any ideas how I can ideally resolve the warning, or at least let Room know it's not an issue?

PS: Class / variable names have been changed, for privacy & simplicity.

Warnings

com.example.Entity's myObjects field has type java.util.List<? extends com.example.MySealedClass> but its getter returns java.util.List<com.example.MySealedClass>. This mismatch might cause unexpected myObjects values in the database when com.example.Entity is inserted into database.
    private java.util.List<? extends com.example.MySealedClass> layoutElements;

com.example.Entity's myMap field has type java.util.Map<java.lang.String, ?> but its getter returns java.util.Map<java.lang.String, java.lang.Object>. This mismatch might cause unexpected myMap values in the database when com.example.Entity is inserted into database.
    private java.util.Map<java.lang.String, ? extends java.lang.Object> myMap;

Entity.kt

    @ColumnInfo(name = "myObjects")
    var myObjects: List<MySealedClass> = listOf(),

    @ColumnInfo(name = "myMap")
    @TypeConverters(MyTypeConverter::class)
    var myMap: Map<String, Any>? = null,

Entity.java (Room generated)

    @org.jetbrains.annotations.NotNull()
    @androidx.room.ColumnInfo(name = "myObjects")
    private java.util.List<? extends com.example.MySealedClass> myObjects;

    @org.jetbrains.annotations.Nullable()
    @androidx.room.ColumnInfo(name = "myMap")
    private java.util.Map<java.lang.String, ? extends java.lang.Object> myMap;

MySealedClass.kt

    sealed class MySealedClass(val x: Int, val y: Boolean = false) : Serializable {
        data class InnerClass(private val z: Int) : MySealedClass(z), Serializable
        data class InnerClass2(private val zz: Int) : MySealedClass(z), Serializable
    }


Solution 1:[1]

I had the same warning and resolved it by changing the data type of the Map from <String, Any> to <String, *>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user13607181