ktorm icon indicating copy to clipboard operation
ktorm copied to clipboard

Wrong json serialization

Open Nook2007 opened this issue 4 years ago • 4 comments

I have abstract class

@JsonTypeInfo(
    use = JsonTypeInfo.Id.NAME,
    include = JsonTypeInfo.As.EXISTING_PROPERTY,
    property = "type"
)
@JsonSubTypes(
    JsonSubTypes.Type(value = SomeSettings::class, name = "SomeSettings"),
)
abstract class Settings : Serializable {
    val type = this::class.java.simpleName  ed
}
data class SomeSettings(var name: String, var value: String) : Settings() {
}

Schema

var settings = json<Settings>("settings").bindTo { it.settings }

Serialization result

{
    "settings": {
        "type": "SomeSettings"
    }
}

name and value fields skipped

Nook2007 avatar Aug 22 '21 06:08 Nook2007

Sorry, this issue is about Jackson, not Ktorm.

vincentlauvlwj avatar Aug 30 '21 11:08 vincentlauvlwj

when using default jackson object mapper(without ktorm module) all ok

val obj = SomeSettings("name", "value")
val str = jacksonObjectMapper().writeValueAsString(obj)

result

{"name":"name","value":"value","type":"SomeSettings"}

Nook2007 avatar Aug 30 '21 12:08 Nook2007

OK, let me check.

vincentlauvlwj avatar Aug 30 '21 12:08 vincentlauvlwj

Any news?

Nook2007 avatar Sep 07 '21 11:09 Nook2007

Sorry, cannot reproduce this issue.

vincentlauvlwj avatar Jan 19 '23 02:01 vincentlauvlwj