ROOM how to store classes with self referance classes inside

Viewed 26
@Entity(tableName = "my_table")
data class Tree (
    @PrimaryKey(autoGenerate = true)
    val id: Int = 0,

    var root: Node? = null
        )


@Parcelize
class Node(
    var parent: Node? = null,
    var left: Node? = null,
    var right: Node? = null,
    var isRoot: Boolean = false,
    var isLeft: Boolean? = null,
    var isRight: Boolean? = null,
    var hash: Int = 0,
) : Parcelable

I Need to store tree with root node, which have other Nodes, when i try it classic i have this in runtime when inserting second node

23315-23516/com.example.testtree E/AndroidRuntime: FATAL EXCEPTION: DefaultDispatcher-worker-1
    Process: com.example.testtree, PID: 23315
    java.lang.StackOverflowError: stack size 1039KB
        at java.lang.String.toString(String.java:2818)
        at java.io.StringWriter.append(StringWriter.java:143)
        at java.io.StringWriter.append(StringWriter.java:41)
        at com.google.gson.stream.JsonWriter.beforeValue(JsonWriter.java:651)


        Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@994b021, Dispatchers.IO]

Pls help me

0 Answers
Related