ReflectionUtils { public static Class<?> determineGenericsType(Class<?> parentClazz, PropertyDescriptor propDescriptor) { Class<?> result = null; if (propDescriptor.getWriteMethod() != null) { result = determineGenericsType(parentClazz, propDescriptor.getWriteMethod(), false); } if (result == null && propDescriptor.getReadMethod() != null) { result = determineGenericsType(parentClazz, propDescriptor.getReadMethod(), true); } return result; } private  ReflectionUtils(); static PropertyDescriptor findPropertyDescriptor(Class<?> objectClass, String fieldName,
                                                            HintContainer deepIndexHintContainer); static DeepHierarchyElement[] getDeepFieldHierarchy(Class<?> parentClass, String field,
                                                               HintContainer deepIndexHintContainer); static Method getMethod(Object obj, String methodName); static Method getMethod(Class<?> clazz, String methodName); static Method findAMethod(Class<?> clazz, String methodName, BeanContainer beanContainer); static PropertyDescriptor[] getPropertyDescriptors(Class<?> objectClass); static Field getFieldFromBean(Class<?> clazz, String fieldName); static Object invoke(Method method, Object obj, Object[] args); static Method getMethod(Class<?> clazz, String name, Class<?>[] parameterTypes); static T newInstance(Class<T> clazz); static Class<?> determineGenericsType(Class<?> parentClazz, PropertyDescriptor propDescriptor); static Class<?> determineGenericsType(Class<?> clazz, Method method, boolean isReadMethod); static Class<?> determineGenericsType(Type type); static Method getNonStandardSetter(Class<?> clazz, String fieldName);  }
@Test public void shouldDetermineGenericTypeForSimpleGenericType() throws Exception { Class<?> clazz = ReflectionUtils.determineGenericsType(ClassWithGenericFields.class.getField("simpleGenericListString").getGenericType()); assertEquals("java.lang.String", clazz.getCanonicalName()); }
@Test public void shouldDetermineGenericTypeForNestedGenericType() throws Exception { Class<?> clazz = ReflectionUtils.determineGenericsType(ClassWithGenericFields.class.getField("nestedGenericListMapStringString").getGenericType()); assertEquals("java.util.Map", clazz.getCanonicalName()); }