and it seems there is a change in behaviour for this use case:
Copy code
@Serializable
class MyClass(
val id: String
) {
val message = "my message"
}
This is my serialization code:
Copy code
val serializer = Json {
// Not relevant to the example but this is the Json serialization config I'm using
ignoreUnknownKeys = true
prettyPrint = true
}
val myClass = MyClass("abc123")
val serialized = serializer.serialize(myClass)
I expect
serialized
to be
Copy code
{
"id": "abc123",
"message": "my message"
}
but I’m getting
Copy code
{
"id": "abc123"
}
m
Marc Knaup
12/18/2020, 3:06 PM
As per CHANGELOG:
encodeDefaults
flag is now set to
false
in the default configuration for JSON, CBOR and Protocol Buffers.
Since
message
defaults to
"my message"
it’s not encoded unless you tell the serializer through your
Json
config.
c
Chris Fillmore
12/18/2020, 3:13 PM
@Marc Knaup thanks for responding. That was my first guess, then I inspected the source and saw that it was already set to
true
, but alas the source was cached and so out of date