[GODRIVER-642] unmarshal private fields Created: 19/Nov/18  Updated: 27/Oct/23  Resolved: 04/Jan/19

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

Type: Improvement Priority: Major - P3
Reporter: Ivan Egorov Assignee: Kristofer Brandow (Inactive)
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

go - 1.11.2
mongo-go-driver - v0.0.18


Attachments: File fail.go     File ok.go    

 Description   

OK:

ok.go

 

$ go run ok.go
 
rs=rs0;
0 ~ 0/transcoder-trans-01:27017;
1 ~ 1/transcoder-trans-02:27017;
2 ~ 2/transcoder-trans-03:27017;

FAIL:

fail.go

 

$ go run fail.go
rs=rs0;
0 ~ 0/;
1 ~ 0/;
2 ~ 0/;

 

 

 



 Comments   
Comment by Kristofer Brandow (Inactive) [ 04/Jan/19 ]

Closing due to inactivity.

Comment by Kristofer Brandow (Inactive) [ 19/Nov/18 ]

Hi vany.egorov,

The reflection library in Go does not allow the setting of private struct fields. If you need the field to be private and want to marshal it, have the type implement the bsoncodec.Proxy interface. This will allow you to return a struct with the private field as public which can then be handled. For unmarhsaling you can implement the bsoncodec.ValueUnmarshaler interface.

Let me know if you have any other questions.

--Kris

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