Re: [go-nuts] Problems with JSON Marshal/UnmarshalText aand maps

2017-11-28 Thread Henrik Johansson
Huh... I could have sworn that I tried it. Thx! On Tue, Nov 28, 2017, 5:59 PM roger peppe wrote: > On 28 November 2017 at 16:30, Henrik Johansson > wrote: > > Ok, thanks for the clarification. > > > > Is there some way to reliably handle these

Re: [go-nuts] Problems with JSON Marshal/UnmarshalText aand maps

2017-11-28 Thread roger peppe
On 28 November 2017 at 16:30, Henrik Johansson wrote: > Ok, thanks for the clarification. > > Is there some way to reliably handle these situations? > I really like the idea of custom value types as keys. As I did in my play.golang.org link, and others have pointed out too,

Re: [go-nuts] Problems with JSON Marshal/UnmarshalText aand maps

2017-11-28 Thread Henrik Johansson
Ok, thanks for the clarification. Is there some way to reliably handle these situations? I really like the idea of custom value types as keys. On Tue, Nov 28, 2017, 5:22 PM roger peppe wrote: > > What tripped me up aside from reusing the map in the example was that in >

Re: [go-nuts] Problems with JSON Marshal/UnmarshalText aand maps

2017-11-28 Thread Henrik Johansson
The time example I have was just an example. I have a trivial struct as key. What tripped me up aside from reusing the map in the example was that in case of errors a value type will still be put in the with it's default value which my or may not for me. I avoided the whole thing by just using

Re: [go-nuts] Problems with JSON Marshal/UnmarshalText aand maps

2017-11-28 Thread Marvin Renich
* Henrik Johansson [171128 07:43]: > But wouldn't unmarshal just overwrite in case of more trivial keys? > > So pointer receivers on the marshaling methods is better. > I think I tried it but something else blew up. While MarshalText can use a value or pointer receiver, it

Re: [go-nuts] Problems with JSON Marshal/UnmarshalText aand maps

2017-11-28 Thread Henrik Johansson
But wouldn't unmarshal just overwrite in case of more trivial keys? So pointer receivers on the marshaling methods is better. I think I tried it but something else blew up. tis 28 nov. 2017 kl 12:55 skrev roger peppe : > You're seeing that behaviour because you're

Re: [go-nuts] Problems with JSON Marshal/UnmarshalText aand maps

2017-11-28 Thread roger peppe
James has it right. Try this: https://play.golang.org/p/VQPBwnh4Jn On 27 November 2017 at 10:13, Henrik Johansson wrote: > Hi, > > https://play.golang.org/p/bLiYSsKL_7 > > I have perhaps missed something simple or misunderstood the contract for > MarshalText/UnmarshalText

Re: [go-nuts] Problems with JSON Marshal/UnmarshalText aand maps

2017-11-27 Thread Henrik Johansson
It seems that time.Time as keys exhibit the same issue: https://play.golang.org/p/-_H3ZD6YLG Is this really intended or a bug? mån 27 nov. 2017 kl 11:25 skrev Henrik Johansson : > There is a discussion here >

Re: [go-nuts] Problems with JSON Marshal/UnmarshalText aand maps

2017-11-27 Thread Henrik Johansson
There is a discussion here https://groups.google.com/forum/#!searchin/golang-dev/json$20map/golang-dev/5gSHNrJQpUI/vZGSGRmUrC0J and an issue here: https://github.com/golang/go/issues/12146 At least the issue has an initial example with a value type key mån 27 nov. 2017 kl 11:21 skrev James

Re: [go-nuts] Problems with JSON Marshal/UnmarshalText aand maps

2017-11-27 Thread James
Think UnmarshalText needs to have a pointer receiver or you'll only be modifying a copy of the struct On 27 November 2017 at 23:13, Henrik Johansson wrote: > Hi, > > https://play.golang.org/p/bLiYSsKL_7 > > I have perhaps missed something simple or misunderstood the

[go-nuts] Problems with JSON Marshal/UnmarshalText aand maps

2017-11-27 Thread Henrik Johansson
Hi, https://play.golang.org/p/bLiYSsKL_7 I have perhaps missed something simple or misunderstood the contract for MarshalText/UnmarshalText but it seems to me that it should work it just doesn't... :) If I uncomment the return of the parse error "BOOM" then I just get a new "default" key with 3