Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
proposal: encoding/json: support json.Unmarshaler for decoding map keys #23455
Please answer these questions before submitting your issue. Thanks!
What did you do?
Unable to JSON marshal/unmarshal a custom primitive type as a map key unless the encoding Text interfaces are implemented instead of the JSON interfaces.
What did you expect to see?
The behaviour should be consistent for each implementation.
What did you see instead?
JSON unmarshalling fails if UnmarshalJSON is implemented instead of UnmarshalText. This is similar for marshalling.
This seems to be enforced in the code on purpose:
And the godoc mentions the same:
So this is "working as intended". I am not sure why it is this way, though. It seems like
If you'd like to propose that