Skip to content

[BUG] StackOverflowError on self reference #203

@ErwinOlieAlliander

Description

@ErwinOlieAlliander

Describe the bug
When mapping an object with a (deep) self reference, I get a StackOverflowError.

To Reproduce

data class MyNode(
    var name: String = "",
    var neighbours: List<MyNode> = mutableListOf(),
)

data class NodeDto(
    val name: String,
    val neighbours: List<NodeDto>,
)

object Mapper : ObjectMappie<MyNode, NodeDto>()

fun main() {

    val a = MyNode("a")
    val b = MyNode("b")
    val c = MyNode("c")

    a.neighbours = listOf(b, c)
    b.neighbours = listOf(a, c)
    c.neighbours = listOf(a, b)

    println(Mapper.map(a).neighbours)
}

Expected behavior
No errors at compile-time and a working mapper.

Kotlin version
2.1.20

Mappie version
2.1.20-1.2.3

Mappie and Kotlin compatibility
yes

Invocation method
Gradle

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions