Consider Vavr collections to be collection like in TypeInformation.
Issue #2511.
This commit is contained in:
@@ -50,10 +50,12 @@ import org.springframework.util.ReflectionUtils;
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
* @author Jürgen Diez
|
||||
*/
|
||||
class TypeDiscoverer<S> implements TypeInformation<S> {
|
||||
|
||||
private static final Class<?>[] MAP_TYPES;
|
||||
private static final Class<?>[] COLLECTION_TYPES;
|
||||
|
||||
static {
|
||||
|
||||
@@ -67,6 +69,19 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
|
||||
} catch (ClassNotFoundException o_O) {}
|
||||
|
||||
MAP_TYPES = mapTypes.toArray(new Class[0]);
|
||||
|
||||
Set<Class<?>> collectionTypes = new HashSet<>();
|
||||
collectionTypes.add(Collection.class);
|
||||
|
||||
try {
|
||||
collectionTypes.add(ClassUtils.forName("io.vavr.collection.Seq", classLoader));
|
||||
} catch (ClassNotFoundException o_O) {}
|
||||
|
||||
try {
|
||||
collectionTypes.add(ClassUtils.forName("io.vavr.collection.Set", classLoader));
|
||||
} catch (ClassNotFoundException o_O) {}
|
||||
|
||||
COLLECTION_TYPES = collectionTypes.toArray(new Class[0]);
|
||||
}
|
||||
|
||||
private final Type type;
|
||||
@@ -332,8 +347,21 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
|
||||
|
||||
return rawType.isArray() //
|
||||
|| Iterable.class.equals(rawType) //
|
||||
|| Collection.class.isAssignableFrom(rawType) //
|
||||
|| Streamable.class.isAssignableFrom(rawType);
|
||||
|| Streamable.class.isAssignableFrom(rawType)
|
||||
|| isCollection();
|
||||
}
|
||||
|
||||
private boolean isCollection() {
|
||||
|
||||
Class<S> type = getType();
|
||||
|
||||
for (Class<?> collectionType : COLLECTION_TYPES) {
|
||||
if (collectionType.isAssignableFrom(type)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||
* Unit tests for {@link TypeDiscoverer}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Jürgen Diez
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TypeDiscovererUnitTests {
|
||||
@@ -178,6 +179,38 @@ public class TypeDiscovererUnitTests {
|
||||
assertThat(type.isSubTypeOf(String.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void considerVavrMapToBeAMap() {
|
||||
|
||||
TypeInformation<io.vavr.collection.Map> type = from(io.vavr.collection.Map.class);
|
||||
|
||||
assertThat(type.isMap()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void considerVavrSetToBeCollectionLike() {
|
||||
|
||||
TypeInformation<io.vavr.collection.Set> type = from(io.vavr.collection.Set.class);
|
||||
|
||||
assertThat(type.isCollectionLike()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void considerVavrSeqToBeCollectionLike() {
|
||||
|
||||
TypeInformation<io.vavr.collection.Seq> type = from(io.vavr.collection.Seq.class);
|
||||
|
||||
assertThat(type.isCollectionLike()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void considerVavrListToBeCollectionLike() {
|
||||
|
||||
TypeInformation<io.vavr.collection.List> type = from(io.vavr.collection.List.class);
|
||||
|
||||
assertThat(type.isCollectionLike()).isTrue();
|
||||
}
|
||||
|
||||
class Person {
|
||||
|
||||
Addresses addresses;
|
||||
|
||||
Reference in New Issue
Block a user