Thank you @Michel. Disturbing that I keep making the same mistake again... On Monday, March 15, 2021 at 2:05:53 PM UTC+1 mlevi...@gmail.com wrote:
> This is because per the Go spec: > https://golang.org/ref/spec#Type_declarations > You're not creating an alias to Token, but defining a new type from it. If > what you are looking for is an alias (meaning to have the "WrappedToken" > identifier refer to the exact same type as Token), you need to do: > > type WrappedToken = Token > > Then all method calls on WrappedToken will be method calls on Token (since > both identifier denote the same type). > > But maybe that is not what you are looking for, if that's the case, there > are other ways around the problem, like type embedding and such. > Hope this helps, > > Le lun. 15 mars 2021 à 13:49, cpu...@gmail.com <cpu...@gmail.com> a > écrit : > >> I've just tried doing something like this in my code: >> >> // Token is an OAuth2 token which includes decoding the expires_in >> attribute >> type Token struct { >> oauth2.Token >> ExpiresIn int `json:"expires_in"` // expiration time in seconds >> } >> >> func (t *Token) UnmarshalJSON(data []byte) error { >> ... >> } >> >> type WrappedToken Token >> >> Only to find out, that unmarshaling a WrappedToken does not call >> Token.UnmarshalJSON which came as a bit of surprise. >> >> I can only guess it's due to how JSON unmarshaling works, but is this the >> intended behaviour? >> >> Kind regards, >> Andreas >> >> -- >> 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...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/golang-nuts/0ceb1917-af61-4259-8695-55eeb0bd6bffn%40googlegroups.com >> >> <https://groups.google.com/d/msgid/golang-nuts/0ceb1917-af61-4259-8695-55eeb0bd6bffn%40googlegroups.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/77f8d500-4f9d-4558-8be5-658230cbb18an%40googlegroups.com.