[GODRIVER-1135] bson encode time.Time , decode is not time.Time format, Created: 13/Jun/19 Updated: 16/Nov/21 Resolved: 11/Jul/19 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | BSON |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Tiansheng Ren | Assignee: | Emmanuel Eppinger (Inactive) |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
bson encode time.Time format data, decode is not time.Time format, but double type data.
test case:
test case result:
|
| Comments |
| Comment by Emmanuel Eppinger (Inactive) [ 11/Jul/19 ] |
|
Hi reage,
If you would like to change the behavior of how time.Time is marshaled and unmarshalled you can create a custom registry and call RegisterTypeMapEntry on it with bson.dateTime and time.Time. See [registry.go|https://github.com/mongodb/mongo-go-driver/blob/master/bson/bsoncodec/registry.go].You can then have the marshalling/unmarshalling behavior you are looking for.
Thanks, Emmanuel |
| Comment by Tiansheng Ren [ 13/Jun/19 ] |
|
myself simple and violent implementation: feature
description:
bson.Encode time.Time to primitive.DateTime. (data type flag:0x09) bson.Decode data type flag 0x09 to time.Time |