Access objects with the Spring Expression Language. Convenient and safe access of deep fields in an object graph.
By default, uses null-safe navigation, but that and other features can be enabled or disabled.
Download the JAR and add it to your app's runtime classpath. A zipped JAR is available on the latest release, e.g. accessor-1.0.0-SNAPSHOT.jar.zip.
Simplest usage lets you do this:
Object value = Accessor.DEFAULT.get(myObject, "some.deep.property");
instead of
Object value = myObject.getSome() != null && myObject.getSome().getDeep() != null && myObject.getSome().getDeep().getProperty();
or
Object value;
try {
value = myObject.getSome().getDeep().getProperty();
}
catch(NullPointerException npe) {}
For more examples, see tests under "src/test/java".
- [Apache Commons BeanUtils: PropertyUtils#getNestedProperty](https://commons.apache.org/proper/commons-beanutils/apidocs/org/apache/commons/beanutils/PropertyUtils.html#getNestedProperty(java.lang.Object, java.lang.String))