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

Comments

Projects
None yet
3 participants
@eaigner
Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor Author

commented Jul 17, 2013

Comment 1:

... in conjunction with `omitempty`
@eaigner

This comment has been minimized.

Copy link
Contributor Author

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

This comment has been minimized.

Copy link
Contributor

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.
You can’t perform that action at this time.