jooby icon indicating copy to clipboard operation
jooby copied to clipboard

Guice module breaks when binding configs of config that has empty list

Open ajcamilo opened this issue 7 years ago • 3 comments

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.

ajcamilo avatar Jul 10 '19 12:07 ajcamilo

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 = []

ajcamilo avatar Jul 11 '19 09:07 ajcamilo

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

jknack avatar Jul 11 '19 11:07 jknack

never mind, found a way of doing it (but still limited basic types)

jknack avatar Jul 11 '19 12:07 jknack