The json package documentation says "an anonymous struct field with a name given in its JSON tag is treated as having that name, rather than being anonymous." I expected the same encoding of both structs in the example above. The same problem exists when unmarshaling values, which is how I bumped into this in the first place.
The text was updated successfully, but these errors were encountered:
As a result, S1 "inherits" JSON marshalling of the embedded time.Time.
I assume you embed time.Time because you want to have all its methods in S1. An alternative to making time.Time a named field is to override MarshalJSON and UnmarshalJSON in S1:
go1.4.2 windows/amd64
https://play.golang.org/p/YGsBuS5Acz
The json package documentation says "an anonymous struct field with a name given in its JSON tag is treated as having that name, rather than being anonymous." I expected the same encoding of both structs in the example above. The same problem exists when unmarshaling values, which is how I bumped into this in the first place.
The text was updated successfully, but these errors were encountered: