Closed ferhatelmas closed 9 years ago
I was stumped on this at first, but did some debugging, and see it is working as designed, unfortunately.
I first tried the experiment with encoding/json in the standard library, and saw the exact same results (as in this defect).
The reason is that, when you embed a value, it inherits methods of the anonymous field. Consequently, agtime.Time embeds time.Time and consequently inherits the (M|Unm)arshal(Text|Binary) methods.
Thus, that method is called when encoding or decoding. That is why the implementation method of the embedded time.Time is called. Unfortunately, there isn't a way to get only methods directly on a type: you can only get (via reflection) all the methods on the method_set (which includes methods inherited via embedding, etc). So, even if we wanted to change the implementation to "ignore" inherited methods from anonymous fields, we can't.
It's a bummer :(
I see so we need to provide relevant (M|Unm)arshal(Text|Binary) and Gob(En|De)code methods if we embed types that provide these methods.
Thanks for explanation, it works after writing a custom one to override provided.
Time struct:
If Time struct was defined as following then it works:
Thanks!