DATACMNS-483 - Added test case for recursive object wrapper resolution.

AbstractRepositoryMetadata now correctly resolves the domain type in case it's nested in multiple levels of wrapper types.
This commit is contained in:
Oliver Gierke
2014-04-22 17:47:41 +02:00
parent c141fb771d
commit 248e314486
2 changed files with 32 additions and 8 deletions

View File

@@ -57,14 +57,7 @@ public abstract class AbstractRepositoryMetadata implements RepositoryMetadata {
* @see org.springframework.data.repository.core.RepositoryMetadata#getReturnedDomainClass(java.lang.reflect.Method)
*/
public Class<?> getReturnedDomainClass(Method method) {
TypeInformation<?> returnTypeInfo = typeInformation.getReturnType(method);
Class<?> rawType = returnTypeInfo.getType();
boolean needToUnwrap = Iterable.class.isAssignableFrom(rawType) || rawType.isArray()
|| QueryExecutionConverters.supports(rawType);
return needToUnwrap ? returnTypeInfo.getComponentType().getType() : rawType;
return unwrapWrapperTypes(typeInformation.getReturnType(method));
}
/*
@@ -104,4 +97,20 @@ public abstract class AbstractRepositoryMetadata implements RepositoryMetadata {
return Arrays.asList(findAllMethod.getParameterTypes()).contains(Pageable.class);
}
/**
* Recursively unwraps well known wrapper types from the given {@link TypeInformation}.
*
* @param type must not be {@literal null}.
* @return
*/
private static Class<?> unwrapWrapperTypes(TypeInformation<?> type) {
Class<?> rawType = type.getType();
boolean needToUnwrap = Iterable.class.isAssignableFrom(rawType) || rawType.isArray()
|| QueryExecutionConverters.supports(rawType);
return needToUnwrap ? unwrapWrapperTypes(type.getComponentType()) : rawType;
}
}