Skip to content

Map keys using custom types not being serialized with MarshalText #459

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

Open
styeung opened this issue May 1, 2020 · 0 comments
Open

Map keys using custom types not being serialized with MarshalText #459

styeung opened this issue May 1, 2020 · 0 comments

Comments

@styeung
Copy link
Contributor

styeung commented May 1, 2020

Assuming jsoniter is supposed to be 100% compatible with encoding/json, it appears that jsoniter does not serialize map keys of custom types correctly, in that it does not use the MarshalText method when provided.

The standard behavior is that any type implementing the TextMarshaler interface should use MarshalText when marshaling itself.

The strange thing is that this incorrect behavior only happens when the map key is a value. When the map key is a pointer, it's fine.

To illustrate what I mean, consider these four scenarios:

You'll notice that the first three scenarios is able to pick up on the custom behavior added by MarshalText, but the fourth one does not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant