Hello. I was previously using serialization-core `...
# serialization
c
Hello. I was previously using serialization-core
1.0.0-RC
and updated to serialization-json
1.0.1
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
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
@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
I set
encodeDefaults = true
and it works now. Thank you!
👍 1