[GODRIVER-410] IsZero and structs Created: 08/May/18  Updated: 17/May/18  Resolved: 17/May/18

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

Type: Improvement Priority: Minor - P4
Reporter: Thomas Geulen Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

It is currently not possible to flag a struct, i.e. time.Time as 'omitempty' because IsZero() return false, due to the missing Zeroer implementation.

Should IsZero also check if the given value is equals to the default value of the struct instead of return false in case of a non-implemented Zeroer interface?



 Comments   
Comment by Githook User [ 17/May/18 ]

Author:

{'email': '38960709+thomasgeulen@users.noreply.github.com', 'username': 'thomasgeulen', 'name': 'Thomas Geulen'}

Message: Merge branch 'master' into GODRIVER-410
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/8daafecc60b87fc95ffc553424bf95b5a561617f

Comment by Githook User [ 17/May/18 ]

Author:

{'email': 'thomas.geulen@csb.com', 'username': 'thomasgeulen', 'name': 'Thomas Geulen'}

Message: GODRIVER-410: Check for omitempty and IsZero before encoding the field.
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/f76a79536aab22c0b249a3168f1999e929c749a9

Comment by Kristofer Brandow (Inactive) [ 15/May/18 ]

Code Review: https://github.com/mongodb/mongo-go-driver/pull/54.

Comment by Kristofer Brandow (Inactive) [ 10/May/18 ]

Hi thomas.geulen,

So the time.Time type does implement a bson.Zeroer, however, the place where we check for zero is after we have already encoded the time.Time value. You fixed this for checking for empty before inline, but it looks like we didn't move the check for omit empty up high enough. If you'd like, send another PR and move the omitempty isZero line to here: 

https://github.com/mongodb/mongo-go-driver/blob/2a25967215f361ca101688d23007a51eb787672d/bson/encode.go#L490.

If you don't have availability to do so, let me know and I'll add it to our backlog. Thanks for the bug report!

--Kris

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