kbson icon indicating copy to clipboard operation
kbson copied to clipboard

allow to not store null using a new Configuration.nonEncodeNull property

Open zigzago opened this issue 4 years ago • 4 comments

Because we can't always add a NonEncodeNull annotation

zigzago avatar Oct 05 '19 21:10 zigzago

https://github.com/Litote/kmongo/issues/104

jershell avatar Oct 07 '19 14:10 jershell

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

jershell avatar Oct 19 '19 14:10 jershell

Hm, in v0.13.0 I look on the point "Hide NullableSerializer, introduce '.nullable' extension instead". Need more time for research

jershell avatar Oct 19 '19 15:10 jershell

@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

jershell avatar Oct 26 '19 14:10 jershell