It's not an "aliased type". Type aliases take the form type A = B and they make the name A be interchangeable with the name B. What you have is a type declaration type A B which creates a fully new type, with a new method set, but the same underlying type as B.
On Fri, May 20, 2022 at 9:28 AM Marcin Romaszewicz <marc...@gmail.com> wrote: > Hi All, > > I've created a simple struct that wraps time.Time because I'd like to > unmarshal it differently from JSON than the default. It works great. > > However, when I pass a type alias of that struct to json.Marshal or > json.Unmarshal, the MarshalJSON and UnmarshalJSON functions aren't invoked, > despite both types conforming to the interfaces. > > Here's the shortest example I could make. > https://go.dev/play/p/pETWQB3CWxV > > This is where this came up: > https://github.com/deepmap/oapi-codegen/issues/579 > > I did find a workaround, in redeclaring the MarshalJSON/UnmarshalJSON on > the aliased type, but I don't understand why this is necessary, and I'm > hoping someone who understands the innards of this better than I do could > enlighten me. > > Thanks, > -- Marcin > > > -- > 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+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/CA%2Bv29LuOa9sHFWxPxqYq_HtiQZ6_pUhCtMUOAL8Yq1X_UvyjJw%40mail.gmail.com > <https://groups.google.com/d/msgid/golang-nuts/CA%2Bv29LuOa9sHFWxPxqYq_HtiQZ6_pUhCtMUOAL8Yq1X_UvyjJw%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAEkBMfE%2Bw0Dj38JnQ%3D3m93ctuE-mQCpAWnMPY%2By-mihoSC2R%2Bg%40mail.gmail.com.