What's the status on null values in protobuf right...
# serialization
p
What's the status on null values in protobuf right now? If I get it correctly protobuf 3 is capable of null values?
g
Isn’t all values in protobuf are essentially nullable (the only way to support full backward compatibility)?
they can be non-nullable only if have default value
Is it Proto2 or 3?
p
It's just the serialization library?
g
What do you mean? Null is supported in general
I clearly see proto annotation on data class
So you serialize/desereali3 it into Proto2?
p
Don't get it. How would I specify that?
g
As I know officially it supports Proto2 only
It proto3 may work, just not sure
Could you show whole stacktrace
p
Sure, but its completely self contained so you can just run it yourself:
Copy code
Exception in thread "main" kotlinx.serialization.SerializationException: null is not supported
	at kotlinx.serialization.internal.TaggedEncoder.encodeTaggedNull(Tagged.kt:37)
	at kotlinx.serialization.internal.TaggedEncoder.encodeNull(Tagged.kt:71)
	at kotlinx.serialization.Encoder$DefaultImpls.encodeNullableSerializableValue(Encoding.kt:260)
	at kotlinx.serialization.internal.TaggedEncoder.encodeNullableSerializableValue(Tagged.kt:22)
	at kotlinx.serialization.internal.TaggedEncoder.encodeNullableSerializableElement(Tagged.kt:124)
	at Test.write$Self(protobug.kt)
	at Test$$serializer.serialize(protobug.kt)
	at Test$$serializer.serialize(protobug.kt:9)
	at kotlinx.serialization.protobuf.ProtoBuf$ProtobufWriter.encodeSerializableValue(ProtoBuf.kt:148)
	at kotlinx.serialization.EncodingKt.encode(Encoding.kt:402)
	at kotlinx.serialization.protobuf.ProtoBuf.dump(ProtoBuf.kt:541)
	at kotlinx.serialization.protobuf.ProtoBuf$Default.dump(ProtoBuf.kt)
	at ProtobugKt.main(protobug.kt:14)
	at ProtobugKt.main(protobug.kt)
g
You should enable nulls:
Copy code
ProtoBuf(encodeDefaults = false)
Essentially protobuf doesn’t have concept of null, only optional with default value, so this flag just skip serialization of this null value