Closed
Description
Hello,
Up to recently we have been using Spring Shell 2.1.2 but after trying to upgrade to later version(s) we have noticed a change in behavior how Converters are called. Also, there seems to be a difference if the command invocation uses named parameters or positional parameters.
Given the below @ShellMetods and a custom Converter (String -> MyType) the results will be as in the table below with different versions of Spring Shell:
@ShellComponent
public class Commands {
@ShellMethod(key="single")
public void single(@ShellOption(value="--value") MyType single)
{
System.out.printf("single: %s%n", single);
}
@ShellMethod(key="list")
public void list(@ShellOption(value="--values") List<MyType> list)
{
System.out.printf("list value: %s%n", list);
}
@ShellMethod(key="array")
public void array(@ShellOption(value="--values") MyType[] array)
{
System.out.printf("array: %s%n", Arrays.toString(array));
}
@ShellMethod(key="set")
public void set(@ShellOption(value="--values") Set<MyType> set)
{
System.out.printf("set: %s%n", set);
}
}
And
@Bean
public Converter<String, MyType> myTypeConverter() {
return new Converter<String, MyType>() {
@Override
public MyType convert(String source) {
return new MyType(source);
}
};
}
The following invocations are used
> list --values a,b
> list a,b
> array --values a,b
> array a,b
The expected behavior would be that the Converter is invoked for each value 'a', 'b' and the result being collected into the correct collection type.
The result is as below.
- Green=OK
- Orange=converter called but with the values as a single
String
("a,b") - Red=converter not called at all (target method called with a
List<String>
)
Spring Shell | list --values a,b | list a,b | array --values a,b | array a,b |
---|---|---|---|---|
2.1.2 | OK | OK | NOK [MyType{value=a,b}] | OK |
2.1.3 | NOK [a, b] | OK | NOK [MyType{value=a,b}] | OK |
2.1.4 | NOK [a, b] | OK | NOK [MyType{value=a,b}] | OK |
2.1.5 | NOK [a, b] | OK | NOK [MyType{value=a,b}] | OK |
2.1.6 | NOK [a,b] | NOK [a,b] | NOK [MyType{value=a,b}] | NOK [MyType{value=a,b}] |
2.1.7 | NOK [a, b] | NOK [a,b] | NOK [MyType{value=a,b}] | NOK [MyType{value=a,b}] |