Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if bean property exist win BeanUtils or similar?

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

like image 701
Suzan Cioc Avatar asked Apr 14 '14 18:04

Suzan Cioc


Video Answer


1 Answers

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.

like image 85
Jason C Avatar answered Oct 10 '22 12:10

Jason C