Skip to content

Kotlin sealed class property is always last despite SORT_PROPERTIES_ALPHABETICALLY #377

@antonkushchn26

Description

@antonkushchn26

Looks like the property from sealed class is always last despite SORT_PROPERTIES_ALPHABETICALLY is set to true.

val om = jacksonObjectMapper().apply { configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true)
}

fun main() {
    om.writeValueAsString(Test(2, 1)) // {"a":1,"b":2}
    val user = User.Customer(UUID.fromString("7c183904-63f7-40d3-936b-7f4ae7f96189"))
    om.writeValueAsString(user) // {"userId":"7c183904-63f7-40d3-936b-7f4ae7f96189","type":"customer"}
}

data class Test(
    val b: Int,
    val a: Int
)

sealed class User(val type: String) {
    data class Customer(val userId: UUID) : User("customer")
    data class Employee(val email: String) : User("employee")
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions