[GODRIVER-2711] Deprecate all "*Append", "*WithRegistry", and "*WithContext" functions in the "bson" package Created: 22/Dec/22  Updated: 28/Oct/23  Resolved: 22/May/23

Status: Closed
Project: Go Driver
Component/s: BSON
Affects Version/s: None
Fix Version/s: 1.12.0

Type: Improvement Priority: Unknown
Reporter: Matt Dale Assignee: Matt Dale
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Epic Link: Go Driver 2.0 Prep
Quarter: FY24Q1
Documentation Changes: Not Needed
Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

The *Append, *WithRegistry, and *WithContext functions in the bson package are redundant and can be replaced by creating and configuring an Encoder or Decoder.

Replacement Examples

Marshal

The MarshalAppend function can be replaced with:

dst := new(bytes.Buffer)
bson.NewEncoder(dst).Encode(val)

The MarshalExtJSONAppend function can be replaced with:

dst := new(bytes.Buffer)
bson.NewExtJSONEncoder(dst).Encode(val)

The Marshal*WithRegistry functions can be replaced with:

dst := new(bytes.Buffer)
enc := bson.NewEncoder(dst)
enc.SetRegistry(reg)
enc.Encode(val)

The MarshalExtJSON*WithRegistry functions can be replaced with:

dst := new(bytes.Buffer)
enc := bson.NewExtJSONEncoder(dst)
enc.SetRegistry(reg)
enc.Encode(val)

The Marshal*WithContext functions can be replaced with:

dst := new(bytes.Buffer)
enc := bson.NewEncoder(dst)
enc.SetRegistry(reg)
enc.SetMinSize(true)
enc.Encode(val)

Unmarshal

The UnmarshalAppend function can be replaced with:

dec := bson.NewDecoder(bytes.NewReader(data))
dec.Decode(val)

The UnmarshalExtJSONAppend function can be replaced with:

dec := bson.NewExtJSONDecoder(bytes.NewReader(data))
dec.Decode(val)

The Unmarshal*WithRegistry functions can be replaced with:

dec := bson.NewDecoder(bytes.NewReader(data))
dec.SetRegistry(reg)
dec.Decode(val)

The UnmarshalExtJSON*WithRegistry functions can be replaced with:

dec := bson.NewExtJSONDecoder(bytes.NewReader(data))
dec.SetRegistry(reg)
dec.Decode(val)

The Unmarshal*WithContext functions can be replaced with:

dec := bson.NewDecoder(bytes.NewReader(data))
dec.SetRegistry(reg)
dec.SetTruncate(true)
dec.DefaultDocumentM()
dec.Decode(val)

Encoder/Decoder

The NewEncoderWithContext function can be replaced with:

dst := new(bytes.Buffer)
enc := NewEncoder(dst)
enc.SetRegistry(reg)
enc.SetMinSize(true)

The NewDecoderWithContext function can be replaced with:

dec := bson.NewDecoder(bytes.NewReader(data))
dec.SetRegistry(reg)
dec.SetTruncate(true)
dec.DefaultDocumentM()

Definition of done

  • Deprecate all package functions and RawValue methods ending with *Append, *WithRegistry, or *WithContext.
  • Add example tests that describe how to replace the functionality offered by all deprecated functions.


 Comments   
Comment by Githook User [ 19/May/23 ]

Author:

{'name': 'Matt Dale', 'email': '9760375+matthewdale@users.noreply.github.com', 'username': 'matthewdale'}

Message: GODRIVER-2711 Deprecate BSON *Append and *With functions. (#1251)

Co-authored-by: Preston Vasquez <prestonvasquez@icloud.com>
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/c58a3649a072657d9ee4c0b3e85f821b919a8bff

Comment by Matt Dale [ 17/May/23 ]

PR: https://github.com/mongodb/mongo-go-driver/pull/1251

Generated at Thu Feb 08 08:39:12 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.