Skip to content

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

Open
@styeung

Description

@styeung

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions