Null safe retrieve property value using BeanUtils

434 Views Asked by At

I am using BeanUtils.getProperty(...) in order to retrieve the value of a given property as follows:

BeanUtils.getProperty(input, myFieldName);

But when the desired field name is not present in the input hashmap, I am getting the following error:

org.apache.commons.beanutils.NestedNullException: Null property value for 'myFieldName' on bean class 'class java.util.HashMap'
    at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:796)
    at org.apache.commons.beanutils.BeanUtilsBean.getNestedProperty(BeanUtilsBean.java:711)
    at org.apache.commons.beanutils.BeanUtilsBean.getProperty(BeanUtilsBean.java:737)

So, I am wondering if there is any null-safe way to retrieve the value for a given property using BeanUtils.getProperty.

0

There are 0 best solutions below