|
24 | 24 | import java.util.List; |
25 | 25 | import java.util.Map; |
26 | 26 | import java.util.stream.Collectors; |
| 27 | +import java.util.stream.Stream; |
27 | 28 |
|
28 | 29 | /** |
29 | 30 | * Exposes Jooby objects to Guice. This module exposes {@link Environment}, {@link Config} and |
@@ -76,14 +77,23 @@ private void configureResources(ServiceRegistry registry) { |
76 | 77 | Object value = entry.getValue().unwrapped(); |
77 | 78 | if (value instanceof List) { |
78 | 79 | List values = (List) value; |
79 | | - Type listType = values.size() == 0 |
80 | | - ? Types.listOf(String.class) |
81 | | - : Types.listOf(values.get(0).getClass()); |
82 | | - Key key = Key.get(listType, Names.named(name)); |
83 | | - bind(key).toInstance(values); |
| 80 | + componentType(values).forEach(componentType -> { |
| 81 | + Type listType = Types.listOf(componentType); |
| 82 | + Key key = Key.get(listType, Names.named(name)); |
| 83 | + bind(key).toInstance(values); |
| 84 | + }); |
84 | 85 | value = values.stream().map(Object::toString).collect(Collectors.joining(",")); |
85 | 86 | } |
86 | 87 | bindConstant().annotatedWith(named).to(value.toString()); |
87 | 88 | } |
88 | 89 | } |
| 90 | + |
| 91 | + private Stream<Class> componentType(List values) { |
| 92 | + if (values.isEmpty()) { |
| 93 | + // For empty list we generates a binding for primitive wrappers. |
| 94 | + return Stream.of(String.class, Integer.class, Long.class, Float.class, Double.class, |
| 95 | + Boolean.class, Object.class); |
| 96 | + } |
| 97 | + return Stream.of(values.get(0).getClass()); |
| 98 | + } |
89 | 99 | } |
0 commit comments