DATACMNS-167 - Improved Iterable handling in TypeDiscoverer.

If a type implemented Iterable<…> it was currently treated as a collection which might cause inappropriate conversion in the mapping sub-system. We now consider types collection like if they're either Iterable directly or assignable to Collection.
This commit is contained in:
Oliver Gierke
2012-05-02 20:54:16 +02:00
parent 5b0cb1a572
commit aec655a499
2 changed files with 78 additions and 42 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011 the original author or authors.
* Copyright 2011-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -134,6 +134,39 @@ public class TypeDiscovererUnitTests {
assertThat(discoverer.getMapValueType(), is(nullValue()));
}
/**
* @see DATACMNS-167
*/
@Test
@SuppressWarnings("rawtypes")
public void doesNotConsiderTypeImplementingIterableACollection() {
TypeDiscoverer<Person> discoverer = new TypeDiscoverer<Person>(Person.class, null);
TypeInformation reference = ClassTypeInformation.from(Address.class);
TypeInformation<?> addresses = discoverer.getProperty("addresses");
assertThat(addresses.isCollectionLike(), is(false));
assertThat(addresses.getComponentType(), is(reference));
TypeInformation<?> adressIterable = discoverer.getProperty("addressIterable");
assertThat(adressIterable.isCollectionLike(), is(true));
assertThat(adressIterable.getComponentType(), is(reference));
}
class Person {
Addresses addresses;
Iterable<Address> addressIterable;
}
abstract class Addresses implements Iterable<Address> {
}
class Address {
}
class SelfReferencing {
Map<String, SelfReferencingMap> parent;