kbson
kbson copied to clipboard
allow to not store null using a new Configuration.nonEncodeNull property
Because we can't always add a NonEncodeNull annotation
https://github.com/Litote/kmongo/issues/104
It is big trouble because annotation allows mark ObjectId field. We have two way destinate goal, use @Serializable(with = ObjectIdSerializer::class)
or use @nonEncodeNull
.
@ContextualSerialization
lose field type and try to found by value
//// kotlinx/serialization/ContextSerializer.kt
public override fun serialize(encoder: Encoder, obj: T) {
val s = encoder.context.getContextualOrDefault(obj)
encoder.encodeSerializableValue(s, obj)
}
that make imposible get actual serializer by null value I hope may be in next version of kotlinx.serialization they add possibility for fix it
Hm, in v0.13.0 I look on the point "Hide NullableSerializer, introduce '.nullable' extension instead". Need more time for research
@zigzago As variant i can make nonEncodeNullableId property of configuration with @file:UseSerializers(ObjectIdSerializer::class) or another serializer determ. ContextSerializer is not impossible to support