lundi 7 mars 2016

Reflection with Apache Commons BeanUtils/PropertyUtils: Instantiating for NULLs in Path

I'm using Apache BeanUtils/PropertyUtils to get/set nested properties via reflection. But sometimes, there may be a NULL object somewhere in the tree.

e.g.

PropertyUtils.setNestedProperty(object, "a.b.c.d", 4);

if b is NULL, looking in the code for Apache Commons,

if (nestedBean == null) {
         throw new NestedNullException
                ("Null property value for '" + name +
                 "' on bean class '" + bean.getClass() + "'");
}

The behavior I'm looking for is instantiation of the missing object to pad the NULLs. Is such a feature available anywhere? Is this called a "Lazy Path" property?





Aucun commentaire:

Enregistrer un commentaire