[GODRIVER-2119] Implement encoding.Text(Un)Marshaler for primitive.ObjectID Created: 06/Aug/21  Updated: 18/Aug/21  Resolved: 18/Aug/21

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

Type: Improvement Priority: Minor - P4
Reporter: Dylan Kozicki Assignee: Benji Rewis (Inactive)
Resolution: Done Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to GODRIVER-2124 Audit the primitive package for encod... Backlog
Documentation Changes: Not Needed

 Description   

In order to be able to use `primitive.ObjectID` as a map key, and have it marshal correctly into json, it needs to implement the https://pkg.go.dev/encoding?utm_source=godoc#TextUnmarshaler] interface, we use maps like these heavily in our product.



 Comments   
Comment by Benji Rewis (Inactive) [ 18/Aug/21 ]

Thanks again for your contribution dkozicki@scoir.com! Your code should be available as part of the upcoming 1.7.2 release of the Go driver.

Comment by Githook User [ 18/Aug/21 ]

Author:

{'name': 'Dylan M. Kozicki', 'email': 'dylan.kozicki@gmail.com', 'username': 'Luberry'}

Message: GODRIVER-2119 Implement Text(Un)Marshaler for primitive.ObjectID (#715)
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/1b281b832dde3a5bcfe609edaad91f3314d249c1

Comment by Benji Rewis (Inactive) [ 10/Aug/21 ]

Thanks for your report dkozicki@scoir.com!

That seems like a reasonable use case; I’ll assign the team as reviewers to your PR, so we’ll all take a look.

I’ve also filed a separate ticket GODRIVER-2124 to audit the primitive package and make sure we implement MarshalText and UnmarshalText for each type. That way, users can marshal from and unmarshal to maps with keys of any primitive type.

Comment by Dylan Kozicki [ 06/Aug/21 ]

Here is my pr for this issue.

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

Comment by Dylan Kozicki [ 06/Aug/21 ]

may also need to implement text marshaler as well, i'm currently writing a fix.

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