klaxon icon indicating copy to clipboard operation
klaxon copied to clipboard

`JsonObject` created by `toJsonObject` from a derived class will not contain members of any superclass.

Open TreffnonX opened this issue 3 years ago • 1 comments

Superclass members are not included in the JsonObject generated from an object with toJsonObject.

Setup:

class A (val uuid: UUID) {
    var name: String = "Something"
}

class B (val rank: Int, uuid: UUID) : A (uuid) {
    fun toJson() = Klaxon().toJsonObject(this)
}

B(rank = 4, uuid = UUID.randomUUID()).toJson() // will lack members uuid and name.

Expected: JsonObject contains all members of A and B

Actual: JsonObject contains only member of class B

This is very surprising as it works for the toJsonString method. There all members are contained.

The reason is possibly the line obj::class.declaredMemberProperties in class JsonValue, which could be written as obj::class.memberProperties instead.

TreffnonX avatar Dec 18 '21 23:12 TreffnonX

Fixed this in PR #350.

TreffnonX avatar Dec 25 '21 20:12 TreffnonX