Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/json: marshal should not encode zero time #5902

Closed
eaigner opened this issue Jul 17, 2013 · 3 comments
Closed

encoding/json: marshal should not encode zero time #5902

eaigner opened this issue Jul 17, 2013 · 3 comments

Comments

@eaigner
Copy link
Contributor

eaigner commented Jul 17, 2013

Time.MarshalJSON also encodes uninitialized time.Time values.

It would be better if the encoding was guarded with IsZero() to avoid returning
meaningless times.
@eaigner
Copy link
Contributor Author

eaigner commented Jul 17, 2013

Comment 1:

... in conjunction with `omitempty`

@eaigner
Copy link
Contributor Author

eaigner commented Jul 17, 2013

Comment 2:

I don't know if this is even possible in the scope of the Time type, but I guess not.
Maybe another interface like MarshalJSON() would be required to implement this.
    type OmitEmpty interface {
      IsEmptyJSON() bool
    }

@rsc
Copy link
Contributor

rsc commented Jul 17, 2013

Comment 3:

Status changed to Duplicate.

Merged into issue #4357.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants