Skip to content

Feature request: Custom serializer for map keys #53

Description

@WouterGritter

When using a custom type in a map within a config, e.g.:

@Configuration
class MyMessagesConfig {
    Map<MyCustomType, String> translations;
}

With MyCustomType having a @SerializeWith(serializer = ...) annotation (with the serializer serializing to String), I am unable to serialize/deserialize this type:

myplugin.shaded.configlib.ConfigurationException: Cannot select serializer for type 'java.util.Map<myplugin.MyCustomType, java.lang.String>'.
Map keys can only be of simple or enum type.

I recognize that key types are more limited, I presume they can only be of type String and not of any other primitive type. But when having a (de)serializer that serializes to and from Strings, I think this should be possible.

In my usecase, MyCustomType is a glorified enum with some custom logic. The (de)serializer simply gets the name of the type, and fetches the type again by the name when deserializing.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions