You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
Assuming
jsoniter
is supposed to be 100% compatible withencoding/json
, it appears that jsoniter does not serialize map keys of custom types correctly, in that it does not use theMarshalText
method when provided.The standard behavior is that any type implementing the
TextMarshaler
interface should useMarshalText
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.The text was updated successfully, but these errors were encountered: