DATACMNS-1484 - Fixed too aggressive conversion to Streamable in IterableToStreamableConverter.

We now explicitly check for the target type to be assignable to Streamable to opt into conversion. Without that check, every collection returned from a method declaring Iterable as return type would've been converted into a Streamable by accident.

Related ticket: DATACMNS-1430.
This commit is contained in:
Oliver Drotbohm
2019-02-21 00:17:29 +01:00
parent d12801a7b0
commit dd0848b186
2 changed files with 13 additions and 0 deletions

View File

@@ -699,6 +699,10 @@ public abstract class QueryExecutionConverters {
@Override
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
if (sourceType.isAssignableTo(targetType)) {
return false;
}
if (!Iterable.class.isAssignableFrom(sourceType.getType())) {
return false;
}

View File

@@ -355,6 +355,15 @@ public class QueryExecutionConvertersUnitTests {
.containsExactly("foo");
}
@Test // DATACMNS-1484
public void doesNotConvertCollectionToStreamableIfReturnTypeIsIterable() {
List<String> source = Arrays.asList("1", "2");
assertThat(conversionService.convert(source, Iterable.class)).isSameAs(source);
}
interface Sample {
Page<String> pages();