views:

702

answers:

3

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.

+1  A: 

Try using

public static BeanInfo getBeanInfo(Class<?> beanClass, Introspector.USE_ALL_BEANINFO);

and see if this yields the result you're looking for.

MetroidFan2002
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().
Steve Kuo
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.
MetroidFan2002
A: 

In such a case, you should write a custom BeanInfo class.

Damien B
note that you'll need to define getAdditionalBeanInfo() if you have define a custom BeanInfo
Scott Stanchfield
+1  A: 

This issue is covered in Sun bug java.beans.Introspector doesn't work for interfaces

Phil