You're seeing that behaviour because you're unmarshaling into the same map
you started with, and encoding/json doesn't zero existing maps before
unmarshaling into them.

You see two members in the map because time.Now returns a time with a
monotonic time but an unmarshaled time doesn't contain a monotonic time.

This works OK: https://play.golang.org/p/KJk4iR3D3D

On 27 November 2017 at 10:53, Henrik Johansson <dahankz...@gmail.com> wrote:
> 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 <dahankz...@gmail.com>:
>>
>> 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 <proglot...@gmail.com>:
>>>
>>> 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 <dahankz...@gmail.com>
>>> wrote:
>>>>
>>>> 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 underscores.
>>>>
>>>> Anyone knows what I missed?
>>>>
>>>> Thx,
>>>> Henrik
>>>>
>>>> --
>>>> 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.
>>>> For more options, visit https://groups.google.com/d/optout.
>
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to