kotlinx.serialization icon indicating copy to clipboard operation
kotlinx.serialization copied to clipboard

ProtoBuf cannot deserialize the Map from `rs/prost` if its value equals the default value

Open zhangz1han opened this issue 1 month ago • 1 comments

Describe the bug

For mutableMapOf("key" to ""),

KotlinX Serialization ProtoBuf encodes both the key and value. Serialization and deserialization are fine.

However, in rs/prost, because the value is equal to the default value, it is omitted during encoding, so the final binary only contains the key.

When KotlinX Serialization ProtoBuf attempts to deserialize it, it throws a SerializationException: Element 'value' is missing.

rs/prost believes their implementation conforms to the specification: tokio-rs/prost/issues/99

Environment

  • Kotlin version: 2.2.21
  • Library version: 1.9.0

zhangz1han avatar Nov 17 '25 15:11 zhangz1han

Original discussion suggests that not writing a value in a map is to-spec, but contradicts most default proto implementations in other languages. It's an optional/default problem again, but I think it makes sense to fix it on our side. Although, I do not know if they do this optimization for non-primitives as well; in that case, we won't be able to restore them.

sandwwraith avatar Nov 24 '25 11:11 sandwwraith