Workaround ResolvableType.forClassWithGenerics bug

Temporarily work around SPR-16456
pull/11886/head
Phillip Webb 7 years ago
parent 60d525e732
commit f24c92c658

@ -40,7 +40,7 @@ class CollectionBinder extends IndexedElementsBinder<Collection<Object>> {
AggregateElementBinder elementBinder) { AggregateElementBinder elementBinder) {
Class<?> collectionType = (target.getValue() == null ? target.getType().resolve() Class<?> collectionType = (target.getValue() == null ? target.getType().resolve()
: List.class); : List.class);
ResolvableType aggregateType = ResolvableType.forClassWithGenerics(List.class, ResolvableType aggregateType = forClassWithGenerics(List.class,
target.getType().asCollection().getGenerics()); target.getType().asCollection().getGenerics());
ResolvableType elementType = target.getType().asCollection().getGeneric(); ResolvableType elementType = target.getType().asCollection().getGeneric();
IndexedCollectionSupplier result = new IndexedCollectionSupplier( IndexedCollectionSupplier result = new IndexedCollectionSupplier(

@ -79,8 +79,8 @@ abstract class IndexedElementsBinder<T> extends AggregateBinder<T> {
ConfigurationProperty property = source.getConfigurationProperty(root); ConfigurationProperty property = source.getConfigurationProperty(root);
if (property != null) { if (property != null) {
Object aggregate = convert(property.getValue(), aggregateType); Object aggregate = convert(property.getValue(), aggregateType);
ResolvableType collectionType = ResolvableType ResolvableType collectionType = forClassWithGenerics(
.forClassWithGenerics(collection.get().getClass(), elementType); collection.get().getClass(), elementType);
Collection<Object> elements = convert(aggregate, collectionType); Collection<Object> elements = convert(aggregate, collectionType);
collection.get().addAll(elements); collection.get().addAll(elements);
} }
@ -140,6 +140,17 @@ abstract class IndexedElementsBinder<T> extends AggregateBinder<T> {
return ResolvableTypeDescriptor.forType(type).convert(conversionService, value); 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 * {@link AggregateBinder.AggregateSupplier AggregateSupplier} for an indexed
* collection. * collection.

Loading…
Cancel
Save