DATACMNS-697 - TypeDiscoverer now considers field-local generics information.
In case we create a ParameterizedTypeInformation for a property we now also analyze the field-local generics information and add the discovered type mappings to the type variable map.
This commit is contained in:
@@ -100,10 +100,21 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
|
||||
return new ClassTypeInformation((Class<?>) fieldType);
|
||||
}
|
||||
|
||||
Map<TypeVariable, Type> variableMap = GenericTypeResolver.getTypeVariableMap(resolveType(fieldType));
|
||||
Class<S> resolveType = resolveType(fieldType);
|
||||
Map<TypeVariable, Type> variableMap = new HashMap<TypeVariable, Type>();
|
||||
variableMap.putAll(GenericTypeResolver.getTypeVariableMap(resolveType));
|
||||
|
||||
if (fieldType instanceof ParameterizedType) {
|
||||
|
||||
ParameterizedType parameterizedType = (ParameterizedType) fieldType;
|
||||
|
||||
TypeVariable<Class<S>>[] typeParameters = resolveType.getTypeParameters();
|
||||
Type[] arguments = parameterizedType.getActualTypeArguments();
|
||||
|
||||
for (int i = 0; i < typeParameters.length; i++) {
|
||||
variableMap.put(typeParameters[i], arguments[i]);
|
||||
}
|
||||
|
||||
return new ParameterizedTypeInformation(parameterizedType, this, variableMap);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2014 the original author or authors.
|
||||
* Copyright 2011-2015 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.
|
||||
@@ -25,6 +25,7 @@ import java.lang.reflect.Type;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -125,6 +126,17 @@ public class ParameterizedTypeUnitTests {
|
||||
assertThat(type.getActualType(), is(type));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-697
|
||||
*/
|
||||
@Test
|
||||
public void usesLocalGenericInformationOfFields() {
|
||||
|
||||
TypeInformation<NormalizedProfile> information = ClassTypeInformation.from(NormalizedProfile.class);
|
||||
TypeInformation<?> valueType = information.getProperty("education2.data").getComponentType();
|
||||
assertThat(valueType.getProperty("value").getType(), is(typeCompatibleWith(Education.class)));
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
class Localized<S> extends HashMap<Locale, S> {
|
||||
S value;
|
||||
@@ -151,4 +163,21 @@ public class ParameterizedTypeUnitTests {
|
||||
class Second {
|
||||
Parameterized<String> property;
|
||||
}
|
||||
|
||||
// see DATACMNS-697
|
||||
|
||||
class NormalizedProfile {
|
||||
|
||||
ListField<Education> education2;
|
||||
}
|
||||
|
||||
class ListField<L> {
|
||||
List<Value<L>> data;
|
||||
}
|
||||
|
||||
class Value<T> {
|
||||
T value;
|
||||
}
|
||||
|
||||
class Education {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user