[go-nuts] Re: How to correctly json.Unmarshal struct whose embedded structs define UnmarshalJSON

2020-01-01 Thread Ben Bullock
On Thursday, 2 January 2020 15:01:15 UTC+9, Glen Huang wrote: > > @Ben > > My real world use case is that I have these types that dealing with user > signing up/loging in > > type LogIn struct { > Name string > Password string > } > > type SignUp struct { > Name string > Password string

[go-nuts] Re: How to correctly json.Unmarshal struct whose embedded structs define UnmarshalJSON

2020-01-01 Thread Glen Huang
@Ben My real world use case is that I have these types that dealing with user signing up/loging in type LogIn struct { Name string Password string } type SignUp struct { Name string Password string Gender string } I was hoping that I cloud embed LogIn inside SignUp, to eliminate d

[go-nuts] Re: How to correctly json.Unmarshal struct whose embedded structs define UnmarshalJSON

2020-01-01 Thread Ben Bullock
On Tuesday, 31 December 2019 19:21:07 UTC+9, Glen Huang wrote: > > I want to unmarshal a struct that contains embedded structs: > > type Parent struct { > Child > P int > } > > > type Child struct { > Grandchild > C int > } > > > type Grandchild struct { > G int > } > > The problem is that

[go-nuts] Re: How to correctly json.Unmarshal struct whose embedded structs define UnmarshalJSON

2020-01-01 Thread Space A.
1. I think it's not correct to use terms "parent" and "child", as Go is not an OOP language. 2. Please note that what you call a Child is actually a Parent, and vice versa. This puts a lot of confusion. 3. Embedding struct will get methods of embedded (depending on whether they've been defined f

[go-nuts] Re: How to correctly json.Unmarshal struct whose embedded structs define UnmarshalJSON

2019-12-31 Thread Glen Huang
After thinking more about it, I start to feel that maybe using embedded structs is generally a bad idea with dealing with json? Is the correct solution here to use explicit fields? BTW, happy New Year everyone. On Tuesday, December 31, 2019 at 6:21:07 PM UTC+8, Glen Huang wrote: > > I want to u