Fix option type parsing
- In `CommandRegistration` add `ResolvableType` for `OptionSpec` giving more spesific handling of a type. - In `CommandParser` handle source and target types so that we have generics with `List`, `Set` and arrays working better. - In `HandlerMethodArgumentResolver` add better handling for `ConversionService` for generic types. - In `StandardMethodTargetRegistrar` add better types via `ResolvableType` now that `CommandRegistration` support it. - In `OptionConversionCommands` remove converter from `String` to `Set` as now things should work as is if generic in a `Set` has a converter. - Backport #694 #699 - Fixes #700
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package org.springframework.shell.standard;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -501,4 +502,31 @@ public class StandardMethodTargetRegistrarTests {
|
||||
public void foo1(@ShellOption("x") boolean arg1) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void OptionWithCustomType() {
|
||||
applicationContext = new AnnotationConfigApplicationContext(OptionWithCustomType.class);
|
||||
registrar = new StandardMethodTargetRegistrar(applicationContext, builder);
|
||||
registrar.register(catalog);
|
||||
|
||||
assertThat(catalog.getRegistrations().get("foo1")).isNotNull();
|
||||
assertThat(catalog.getRegistrations().get("foo1")).satisfies(reg -> {
|
||||
assertThat(reg.getOptions().get(0)).satisfies(option -> {
|
||||
assertThat(option.getType().getGeneric(0).getType()).isEqualTo(Pojo.class);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@ShellComponent
|
||||
public static class OptionWithCustomType {
|
||||
|
||||
@ShellMethod(value = "foo1", prefix = "-")
|
||||
public void foo1(@ShellOption Set<Pojo> arg1) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Pojo {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user