Class FieldAccessor

Object
FieldAccessor

public class FieldAccessor extends Object
Utilities to access a Field of an AnchorBean.
Author:
Owen Feehan
  • Method Details

    • fieldFromBean

      public static Optional<Object> fieldFromBean(AnchorBean<?> bean, Field field) throws IllegalAccessException, BeanMisconfiguredException
      Retrieves the value of a Field from a AnchorBean.
      Parameters:
      bean - the bean
      field - the field to retrieve a value from
      Returns:
      the value, it it exists, or Optional.empty() if it doesn't exist and the bean is marked as optional.
      Throws:
      IllegalAccessException - if reflection tries to access a property it has no permissions for.
      BeanMisconfiguredException - if no value exists for the field (and it's not marked as optional).
    • isFieldAnnotatedAsOptional

      public static boolean isFieldAnnotatedAsOptional(Field field)
      Is a particular Field on a AnchorBean marked as optional?
      Parameters:
      field - the field
      Returns:
      true iff it is marked as optional.