Class AnyBeanReader

java.lang.Object
org.klojang.invoke.AnyBeanReader

public final class AnyBeanReader extends Object
A dynamic bean reader class for arbitrary types of beans. This class uses the java.lang.invoke package instead of reflection to read bean properties. Yet it still uses reflection to identify the getter methods of the bean class. Therefore, if you use this class from within a Java module you must open the module to the naturalis-common module.
Author:
Ayco Holleman
  • Constructor Details

    • AnyBeanReader

      public AnyBeanReader()
      Creates a new AnyBeanReader. JavaBeans naming conventions will be applied regarding which methods qualify as getters.
    • AnyBeanReader

      public AnyBeanReader(boolean strictNaming)
      Creates a new AnyBeanReader.
      Parameters:
      strictNaming - if false, all methods with a zero-length parameter list and a non-void return type, except getClass(), hashCode() and toString(), will be regarded as getters. Otherwise JavaBeans naming conventions will be applied regarding which methods qualify as getters. By way of exception, methods returning a Boolean are allowed to have a name starting with "is" (just like methods returning a boolean). The strictNaming parameter is quietly ignored for record classes. Records are always processed as though strictNaming were false.
  • Method Details

    • read

      public <U> U read(Object bean, String property) throws NoSuchPropertyException
      Returns the value of the specified property on the specified bean. If the property does not exist a NoSuchPropertyException is thrown.
      Type Parameters:
      U - the return type
      Parameters:
      bean - the bean instance
      property - the property
      Returns:
      its value
      Throws:
      NoSuchPropertyException - if the specified property does not exist