Can ProtoBuf serialize a class with nullable prope...
# serialization
i
Can ProtoBuf serialize a class with nullable properties? I try:
Copy code
fun main() {
    @Serializable data class Foo(val nn : Int?)

    val s = ProtoBuf.encodeToByteArray(Foo.serializer(), Foo(null))
}
But get:
Copy code
Exception in thread "main" kotlinx.serialization.SerializationException:
 'null' is not supported in ProtoBuf
I've also tried using:
Copy code
val s = ProtoBuf { encodeDefaults = false }.encodeToByteArray(Foo.serializer(), Foo(null))
But this doesn't help. Any pointers appreciated.
v
Just a wild guess from what you have shown. Maybe if you define
null
as default value (and if necessary define not to encode default values) it might work as then there is no need to encode the unsupported
null
👍 1
i
Ah, yes - thank you, that worked!