Thread
#serialization
    Chris Fillmore

    Chris Fillmore

    1 year ago
    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:
    @Serializable
    class MyClass(
      val id: String
    ) {
      val message = "my message"
    }
    This is my serialization 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
    {
      "id": "abc123",
      "message": "my message"
    }
    but I’m getting
    {
      "id": "abc123"
    }
    m

    Marc Knaup

    1 year ago
    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.
    Chris Fillmore

    Chris Fillmore

    1 year ago
    @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!