Guice module breaks when binding configs of config that has empty list
Guice module breaks when binding configs of config that has empty list. (Jooby 2.0)
In JoobyModule class, line 69:
if (value instanceof List) {
List values = (List) value;
Type listType = Types.listOf(values.iterator().next().getClass());
Key key = Key.get(listType, Names.named(name));
bind(key).toInstance(values);
value = values.stream().map(Object::toString).collect(Collectors.joining(","));
}
This will break if the config has:
some.property = []
I understand the problem that this is trying to resolve. But somehow this worked in jooby 1.x.
I checked your commit that resolves this issue, and this does not work if my config is a list of numbers or durations.
@Inject
ExampleClass(@Named("some.config.ints") List<Integer> ints){
...
And config:
some.config.ints = []
on empty list, it is impossible to know the right type and due Guice is a strong type DI framework we can't do the binding. That's why on empty list I fallback to String
never mind, found a way of doing it (but still limited basic types)