I just noticed that java.beans.Introspector getBeanInfo does not pickup any superinterface's properties. Example:
public interface Person {
String getName();
}
public interface Employee extends Person {
int getSalary();
}
Introspecting on Employee only yields salary even though name is inherited from Person.
Why is this? I would rather not have to use reflection to get all the getters.
From stackoverflow
-
Try using
public static BeanInfo getBeanInfo(Class<?> beanClass, Introspector.USE_ALL_BEANINFO);and see if this yields the result you're looking for.
Steve Kuo : I tried that and it didn't work. My solution was introspect the superclass and parent interfaces by calling the class's getInterfaces() and getSuperclass().MetroidFan2002 : Do you only want the properties? You can get the property descriptors from BeanInfo, I believe it contains all the properties including ones from superclasses. -
In such a case, you should write a custom BeanInfo class.
Scott Stanchfield : note that you'll need to define getAdditionalBeanInfo() if you have define a custom BeanInfo -
This issue is covered in Sun bug java.beans.Introspector doesn't work for interfaces
0 comments:
Post a Comment