@@ -60,16 +60,30 @@ type Zeroer interface {
60
60
61
61
// StructCodec is the Codec used for struct values.
62
62
//
63
- // Deprecated: Use [go.mongodb.org/mongo-driver/bson.NewRegistry] to get a registry with the
64
- // StructCodec registered.
63
+ // Deprecated: StructCodec will not be directly configurable in Go Driver 2.0.
64
+ // To configure the struct encode and decode behavior, use the configuration
65
+ // methods on a [go.mongodb.org/mongo-driver/bson.Encoder] or
66
+ // [go.mongodb.org/mongo-driver/bson.Decoder]. To configure the struct encode
67
+ // and decode behavior for a mongo.Client, use
68
+ // [go.mongodb.org/mongo-driver/mongo/options.ClientOptions.SetBSONOptions].
69
+ //
70
+ // For example, to configure a mongo.Client to omit zero-value structs when
71
+ // using the "omitempty" struct tag, use:
72
+ //
73
+ // opt := options.Client().SetBSONOptions(&options.BSONOptions{
74
+ // OmitZeroStruct: true,
75
+ // })
76
+ //
77
+ // See the deprecation notice for each field in StructCodec for the corresponding
78
+ // settings.
65
79
type StructCodec struct {
66
80
cache sync.Map // map[reflect.Type]*structDescription
67
81
parser StructTagParser
68
82
69
83
// DecodeZeroStruct causes DecodeValue to delete any existing values from Go structs in the
70
84
// destination value passed to Decode before unmarshaling BSON documents into them.
71
85
//
72
- // Deprecated: Use bson.Decoder.ZeroStructs instead.
86
+ // Deprecated: Use bson.Decoder.ZeroStructs or options.BSONOptions.ZeroStructs instead.
73
87
DecodeZeroStruct bool
74
88
75
89
// DecodeDeepZeroInline causes DecodeValue to delete any existing values from Go structs in the
@@ -82,7 +96,7 @@ type StructCodec struct {
82
96
// MyStruct{}) as empty and omit it from the marshaled BSON when the "omitempty" struct tag
83
97
// option is set.
84
98
//
85
- // Deprecated: Use bson.Encoder.OmitZeroStruct instead.
99
+ // Deprecated: Use bson.Encoder.OmitZeroStruct or options.BSONOptions.OmitZeroStruct instead.
86
100
EncodeOmitDefaultStruct bool
87
101
88
102
// AllowUnexportedFields allows encoding and decoding values from un-exported struct fields.
@@ -95,7 +109,8 @@ type StructCodec struct {
95
109
// a duplicate field in the marshaled BSON when the "inline" struct tag option is set. The
96
110
// default value is true.
97
111
//
98
- // Deprecated: Use bson.Encoder.ErrorOnInlineDuplicates instead.
112
+ // Deprecated: Use bson.Encoder.ErrorOnInlineDuplicates or
113
+ // options.BSONOptions.ErrorOnInlineDuplicates instead.
99
114
OverwriteDuplicatedInlinedFields bool
100
115
}
101
116
@@ -104,8 +119,8 @@ var _ ValueDecoder = &StructCodec{}
104
119
105
120
// NewStructCodec returns a StructCodec that uses p for struct tag parsing.
106
121
//
107
- // Deprecated: Use [go.mongodb.org/mongo-driver/bson.NewRegistry] to get a registry with the
108
- // StructCodec registered .
122
+ // Deprecated: NewStructCodec will not be available in Go Driver 2.0. See
123
+ // [ StructCodec] for more details .
109
124
func NewStructCodec (p StructTagParser , opts ... * bsonoptions.StructCodecOptions ) (* StructCodec , error ) {
110
125
if p == nil {
111
126
return nil , errors .New ("a StructTagParser must be provided to NewStructCodec" )
0 commit comments