diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/CollectionBinder.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/CollectionBinder.java index 8a14562a61..b89b6c2e2c 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/CollectionBinder.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/CollectionBinder.java @@ -40,7 +40,7 @@ class CollectionBinder extends IndexedElementsBinder> { AggregateElementBinder elementBinder) { Class collectionType = (target.getValue() == null ? target.getType().resolve() : List.class); - ResolvableType aggregateType = ResolvableType.forClassWithGenerics(List.class, + ResolvableType aggregateType = forClassWithGenerics(List.class, target.getType().asCollection().getGenerics()); ResolvableType elementType = target.getType().asCollection().getGeneric(); IndexedCollectionSupplier result = new IndexedCollectionSupplier( diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/IndexedElementsBinder.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/IndexedElementsBinder.java index 7faa52982e..0c9901d882 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/IndexedElementsBinder.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/IndexedElementsBinder.java @@ -79,8 +79,8 @@ abstract class IndexedElementsBinder extends AggregateBinder { ConfigurationProperty property = source.getConfigurationProperty(root); if (property != null) { Object aggregate = convert(property.getValue(), aggregateType); - ResolvableType collectionType = ResolvableType - .forClassWithGenerics(collection.get().getClass(), elementType); + ResolvableType collectionType = forClassWithGenerics( + collection.get().getClass(), elementType); Collection elements = convert(aggregate, collectionType); collection.get().addAll(elements); } @@ -140,6 +140,17 @@ abstract class IndexedElementsBinder extends AggregateBinder { return ResolvableTypeDescriptor.forType(type).convert(conversionService, value); } + // Work around for SPR-16456 + protected static ResolvableType forClassWithGenerics(Class type, + ResolvableType... generics) { + ResolvableType[] resolvedGenerics = new ResolvableType[generics.length]; + for (int i = 0; i < generics.length; i++) { + resolvedGenerics[i] = forClassWithGenerics(generics[i].resolve(), + generics[i].getGenerics()); + } + return ResolvableType.forClassWithGenerics(type, resolvedGenerics); + } + /** * {@link AggregateBinder.AggregateSupplier AggregateSupplier} for an indexed * collection.