DATACMNS-211 - Fixed component type resolving for arrays.

ClassTypeInformation does not resolve nested array types anymore as a multidimensional array in fact has a component type of an array of one dimension less, e.g. String[][].getComponentType() -> String[].
This commit is contained in:
Oliver Gierke
2012-08-16 12:40:51 +02:00
parent c6b04618b9
commit 0fc753f151
2 changed files with 9 additions and 21 deletions

View File

@@ -29,7 +29,6 @@ import java.util.Set;
import java.util.WeakHashMap;
import org.springframework.core.GenericTypeResolver;
import org.springframework.util.Assert;
/**
* {@link TypeInformation} for a plain {@link Class}.
@@ -110,20 +109,6 @@ public class ClassTypeInformation<S> extends TypeDiscoverer<S> {
return type;
}
/*
* (non-Javadoc)
* @see org.springframework.data.util.TypeDiscoverer#getComponentType()
*/
@Override
public TypeInformation<?> getComponentType() {
if (type.isArray()) {
return createInfo(resolveArrayType(type));
}
return super.getComponentType();
}
/*
* (non-Javadoc)
* @see org.springframework.data.util.TypeDiscoverer#isAssignableFrom(org.springframework.data.util.TypeInformation)
@@ -132,10 +117,4 @@ public class ClassTypeInformation<S> extends TypeDiscoverer<S> {
public boolean isAssignableFrom(TypeInformation<?> target) {
return getType().isAssignableFrom(target.getType());
}
private static Type resolveArrayType(Class<?> type) {
Assert.isTrue(type.isArray());
Class<?> componentType = type.getComponentType();
return componentType.isArray() ? resolveArrayType(componentType) : componentType;
}
}

View File

@@ -254,6 +254,15 @@ public class ClassTypeInformationUnitTests {
GenericInterface.class)), is(false));
}
@Test
public void returnsComponentTypeForMultiDimensionalArrayCorrectly() {
TypeInformation<?> information = from(String[][].class);
assertThat(information.getType(), is((Object) String[][].class));
assertThat(information.getComponentType().getType(), is((Object) String[].class));
assertThat(information.getActualType().getActualType().getType(), is((Object) String.class));
}
static class StringMapContainer extends MapContainer<String> {
}