JDK-6473468 : RFE: PropertyDescriptor should support getGenericPropertyType() method
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 6
  • Priority: P5
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_2003
  • CPU: x86
  • Submitted: 2006-09-21
  • Updated: 2011-02-16
Related Reports
Relates :  
Description
A DESCRIPTION OF THE REQUEST :
When the type of a  property is a generic collection type (like List<String>), the existing PropertyDescriptor.getPropertyType() method returns only the "raw" property type of "List".  What is needed is a method like this:

    Type getPropertyGenericType();

that would return the full generic type (List<String>) as obtained from
  getReadMethod()..getGenericReturnType();
or
  getWriteMethod().getGenericParameterTypes()[0];

The other "Descriptor" types should probably have the same enhancement.  Eg, "BeanDescriptor" should have a new method:
    Type getBeanGenericClass();
and so on.


JUSTIFICATION :
When generics were introduced, the "java.lang.reflect.Field" class added a "getGenericType()" type to compliment the existing "getType()" method.
This RFE would just be adding the same capability to the "PropertyDescriptor" class.



CUSTOMER SUBMITTED WORKAROUND :
The only work around is to access the same information through the "java.lang.reflect.*" classes, which defeats the purpose of having the java.beans package in the first place.

Comments
EVALUATION We should not fix this bug because getter and setter can be declared in different classes. The following types will be different in such case: Type getter = propertyDescriptor.getReadMethod().getGenericReturnType(); Type setter = propertyDescriptor.getWriteMethod().getGenericParameterTypes()[0]; So we can't decide what type is expected from the suggested method: Type getPropertyGenericType();
2007-05-25

WORK AROUND It is often possible to use propertyDescriptor.getReadMethod().getGenericReturnType() or propertyDescriptor.getWriteMethod().getGenericParameterTypes()[0].
2006-09-21

EVALUATION I think it is impossible while such info is not accesible via reflection.
2006-09-21