Ability to override default enum type converter
- Dominant language
- Java
- Stars
- 12.7k
- Forks
- 1.7k
- Avg merge
- 11m
- Merged PRs (30d)
- 2
Description
I am trying to leverage type conversion in guice with TimeUnit. I have configuration that comes in via a string in one of many formats that I'd like to be able to convert to TimeUnit instances e.g. I'd like to be able to convert any of "s", "sec", "second", "seconds" to TimeUnit.Seconds. I already have the conversion logic written myself, so I thought I'd be able to do something like:
convertToTypes(Matchers.only(TypeLiteral.get(TimeUnit.class)), new TypeConverter() {
@Override
public Object convert(final String value, final TypeLiteral toType) {
// convert
}
});
However, I get a CreationException due to overlapping matchers (my custom matcher, and the default enum matcher). Most of the discussion I've seen online about this problem is several years old, and at that time it didn't seem possible. Has the situation changed at all? It seems like the above case would be fairly common for enums, at least for me. I often want enum creation to be more permissive than what valueOf() allows for.
Contributor guide
Assessment
This issue has not been assessed yet.