[GODRIVER-401] Support `json:"-"` tags in the bson encoder Created: 02/May/18  Updated: 27/Oct/23  Resolved: 08/Oct/18

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

Type: New Feature Priority: Major - P3
Reporter: Dominic Gregoire Assignee: Kristofer Brandow (Inactive)
Resolution: Gone away Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on GODRIVER-494 BSON Codec Redesign Closed

 Description   

Protobuf has merged https://github.com/golang/protobuf/tree/dev into master on the 30th of april which will cause problems to anyone using protobuf generated code to encode data to bson.

https://groups.google.com/forum/#!topic/protobuf/N-elvFu4dFM

Specifically, they added 3 new fields to all generated structs

```

XXX_NoUnkeyedLiteral struct{}        `json:"-""`

XXX_unrecognized     []byte          `json:"-""`

XXX_sizecache        int32           `json:"-"`

```

The fix is to manually add a `bson:"-"` tag, however this breaks any CI that auto-regenerates protobuf on compilation.

If the `bson` encoder supported reading the json tags it would work seamlessly.

 

 



 Comments   
Comment by Jeff Ithier [ 01/Oct/18 ]

+1 for StructTagParser

Comment by Dominic Gregoire [ 27/Sep/18 ]

krisbrandow

Yes - StructTagParser is a good idea - this will definitely work out.

Best,
D

Comment by Kristofer Brandow (Inactive) [ 27/Sep/18 ]

Hi dgregoire,

A new Decoder and Encoder design will be merged into the codebase when GODRIVER-494 is complete. This will allow users to register a custom StructTagParser with the struct encoder/decoder. This will allow users to parse the json tag as necessary.

Alternatively, you can use the gogo/protobuf library instead of the golang/protobuf one. This library contains support for custom struct tags: https://github.com/gogo/protobuf/blob/master/extensions.md#more-serialization-formats.

Do either of those solutions solve your needs?

Thanks,

Kris

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