I’m attempting to use bsonoptions.SliceCodec().SetEncodeNilAsEmpty(true)
, but I’m having issues building the registry. This is what I have so far:
registry := bsoncodec.NewRegistryBuilder()
bsoncodec.DefaultValueEncoders{}.RegisterDefaultEncoders(registry)
nilSliceCodec := bsoncodec.NewSliceCodec(bsonoptions.SliceCodec().SetEncodeNilAsEmpty(true))
registry.RegisterDefaultEncoder(reflect.Slice, nilSliceCodec)
opts.SetRegistry(registry.Build())
When I do not override the registry, my tests work fine. When I add this hunk of code though, I start getting back this error: no decoder found for interface {}
.
My current guess is that RegisterDefaultEncoders
isn’t registering the proper encoder for interfaces, but I’m a little unclear about how to specify them.
@Isabella_Siu - any ideas on what I might be doing wrong here?