[GODRIVER-712] ObjectId, json-omitempty Created: 17/Dec/18 Updated: 27/Oct/23 Resolved: 07/Jan/19 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | JSON & ExtJSON |
| Affects Version/s: | 0.1.0 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | Dávid Mikuš | Assignee: | Kristofer Brandow (Inactive) |
| Resolution: | Gone away | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
E.g
When an object is marshalled with SomeId == primitive.NilObjectID and omitempty tag, it shouldn't be included in the marshalled string. Now it's marshalled into
|
| Comments |
| Comment by Matthew Browning [ 29/Jan/19 ] |
|
A question related to this. I've decoded the bson data into a struct, want to send it off to the client as json. Looking at the bson.MarshalExtJSON function it seems that it's in a different looking format of JSON than I would want to the client. Is there a way to define my on structure for JSON and omitempty nil object ids? Thanks |
| Comment by Kristofer Brandow (Inactive) [ 17/Dec/18 ] |
|
The encoding/json.Marshal function only checks if an array has a length of zero, not if all of it's values are zero. If you instead use the bson.MarshalExtJSON function it will omit the zero value for primitive.ObjectID. --Kris |