New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: encoding/json: support json.Unmarshaler for decoding map keys #23455
Comments
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 |
Closing, as this is working as intended. |
Well, I left the issue open in case OP wanted to convert it into a proposal, and since I wasn't 100% sure that this is what they meant originally (note how the original title said "marshaling", for example). |
Thanks. Having looked through the previous discussions the current behaviour does make sense. The example seems counterintuitive but consistency for the two interfaces wouldn't actually provide any new desired behaviour so I'll close this issue. |
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.
https://play.golang.org/p/JckXOU4k6FM
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.
System details
The text was updated successfully, but these errors were encountered: