10

Is there ready made routine to check if bean has getter for specific property name given by string?

Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385

1 Answers1

20

You could do this, from BeanUtils:

static boolean propertyExists (Object bean, String property) {
    return PropertyUtils.isReadable(bean, property) && 
           PropertyUtils.isWriteable(bean, property); 
}

As far as I know there isn't a one-liner that encapsulates both of those, since readability / writeability are independent.

If you're only interested in the getter, PropertyUtils.isReadable() alone will work.

Jason C
  • 38,729
  • 14
  • 126
  • 182