-
Notifications
You must be signed in to change notification settings - Fork 425
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
Support for generic types in containers #1401
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the very long delay. I finally have some time to look at picocli again.
I am okay to merge this PR, but I would prefer not to include the UseDefaultConverter
API.
Can you take a look and let me know what you think?
* | ||
* Instances of this class will throw UnsupportedOperationException for {@link #convert(String)} method. | ||
*/ | ||
public static final class UseDefaultConverter implements ITypeConverter<Object> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to introduce this UseDefaultConverter
class as part of this PR?
Applications can use the CommandLine::registerConverter
method:
new CommandLine(new MyApp())
.registerConverter(GenericValue.class, GenericValueConverter.class)
.execute(args);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UseDefaultConverter
is only for use cases when we need to provide converters for multiple parameters and for some of them we simple want to use default, e.g.:
@Option(names = "-D", converter = {UseDefaultConverter.class, GenericValueConverter.class})
Map<String, GenericValue<?>> values;
In this case I would need to provided custom convert for String class also since BuiltIt.StringConverter
is private.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that. Is there any issue with using the CommandLine::registerConverter
method to register the GenericValueConverter
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With global registration there may be issue with type erasure. If I want to use two different converters for same GenericValue<T>
(e.g. in one parameter GenericValue<Integer>
and in other GenericValue<String>
) then I won't be able to this with CommandLine::registerConverter
Okay, I see now, thanks for the clarification. Without the I like to add a bit more functionality before doing a 4.7.0 release, so this may take a bit more time. Would you be open to the idea of splitting this up? |
d220d04
to
43a101c
Compare
Improvement for issue #1396. This will also add
CommandLine.UseDefaultConverter
which can be used as marker for default converter fallback.