FAQ
Hi,

I basically have a struct looking like

type Foobar struct {
     t time.Time `json:"omitempty"`
}

Now when I do

var fb Foobar

and then try to serialize it, I get "t":"0001-01-01T00:00:00Z" instead of
"t" being absent.

So I am just wondering it if makes sense to expect this to work or not.
time.Time implements the JSON interfaces, so I was expecting this to work.

Cheers,
Ondrej

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Denis Bakhtin at Sep 9, 2014 at 12:43 pm
    It is absent :) http://play.golang.org/p/4qwl_njvSS

    2014-09-09 16:24 GMT+04:00 Ondřej Kupka <ondra.cap@gmail.com>:
    Hi,

    I basically have a struct looking like

    type Foobar struct {
    t time.Time `json:"omitempty"`
    }

    Now when I do

    var fb Foobar

    and then try to serialize it, I get "t":"0001-01-01T00:00:00Z" instead of
    "t" being absent.

    So I am just wondering it if makes sense to expect this to work or not.
    time.Time implements the JSON interfaces, so I was expecting this to work.

    Cheers,
    Ondrej

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Nate Brennand at Sep 9, 2014 at 1:42 pm
    @Denis, in your playground link you don’t make the attribute T exposed. The
    attribute must be exposed for the field to ever be marshaled into JSON.
    Also, omitempty must be used after a comma to denote that it’s a property,
    not the name of the field.
    Here’s an updated example: http://play.golang.org/p/Jour5HAKEe

    Your best bet seems to be making the T attribute a pointer, it will be nil
    when uninstantiated.
    http://play.golang.org/p/ud6OLZUrmY

    On Tue, Sep 9, 2014 at 8:43 AM, Denis Bakhtin wrote:

    It is absent :) http://play.golang.org/p/4qwl_njvSS

    2014-09-09 16:24 GMT+04:00 Ondřej Kupka <ondra.cap@gmail.com>:
    Hi,

    I basically have a struct looking like

    type Foobar struct {
    t time.Time `json:"omitempty"`
    }

    Now when I do

    var fb Foobar

    and then try to serialize it, I get "t":"0001-01-01T00:00:00Z" instead of
    "t" being absent.

    So I am just wondering it if makes sense to expect this to work or not.
    time.Time implements the JSON interfaces, so I was expecting this to work.

    Cheers,
    Ondrej

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Denis Bakhtin at Sep 9, 2014 at 1:53 pm
    @Nate, right you are, was inattentive :) thank you.

    2014-09-09 17:42 GMT+04:00 Nate Brennand <natebrennand@gmail.com>:
    @Denis, in your playground link you don’t make the attribute T exposed.
    The attribute must be exposed for the field to ever be marshaled into JSON.
    Also, omitempty must be used after a comma to denote that it’s a
    property, not the name of the field.
    Here’s an updated example: http://play.golang.org/p/Jour5HAKEe

    Your best bet seems to be making the T attribute a pointer, it will be nil
    when uninstantiated.
    http://play.golang.org/p/ud6OLZUrmY

    On Tue, Sep 9, 2014 at 8:43 AM, Denis Bakhtin wrote:

    It is absent :) http://play.golang.org/p/4qwl_njvSS

    2014-09-09 16:24 GMT+04:00 Ondřej Kupka <ondra.cap@gmail.com>:
    Hi,

    I basically have a struct looking like

    type Foobar struct {
    t time.Time `json:"omitempty"`
    }

    Now when I do

    var fb Foobar

    and then try to serialize it, I get "t":"0001-01-01T00:00:00Z" instead
    of "t" being absent.

    So I am just wondering it if makes sense to expect this to work or not.
    time.Time implements the JSON interfaces, so I was expecting this to
    work.

    Cheers,
    Ondrej

    --
    You received this message because you are subscribed to the Google
    Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send
    an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Ian Davis at Sep 9, 2014 at 2:16 pm
    On Tue, Sep 9, 2014, at 01:24 PM, Ondřej Kupka wrote:

    and then try to serialize it, I get "t":"0001-01-01T00:00:00Z"
    instead of "t" being absent.



    See issue
    4357 [1]https://code.google.com/p/go/issues/detail?id=4357



    Ian

    References

    1. https://code.google.com/p/go/issues/detail?id=4357

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedSep 9, '14 at 12:24p
activeSep 9, '14 at 2:16p
posts5
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase