Class FieldUtils


  • public final class FieldUtils
    extends java.lang.Object
    Offers static methods for directly manipulating fields.
    • Constructor Summary

      Constructors 
      Constructor Description
      FieldUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.reflect.Field getField​(java.lang.Class<?> clazz, java.lang.String fieldName)
      Attempts to locate the specified field on the class.
      static java.lang.Object getFieldValue​(java.lang.Object bean, java.lang.String fieldName)
      Returns the value of a (nested) field on a bean.
      static java.lang.Object getProtectedFieldValue​(java.lang.String protectedField, java.lang.Object object)  
      static void setProtectedFieldValue​(java.lang.String protectedField, java.lang.Object object, java.lang.Object newValue)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FieldUtils

        public FieldUtils()
    • Method Detail

      • getField

        public static java.lang.reflect.Field getField​(java.lang.Class<?> clazz,
                                                       java.lang.String fieldName)
                                                throws java.lang.IllegalStateException
        Attempts to locate the specified field on the class.
        Parameters:
        clazz - the class definition containing the field
        fieldName - the name of the field to locate
        Returns:
        the Field (never null)
        Throws:
        java.lang.IllegalStateException - if field could not be found
      • getFieldValue

        public static java.lang.Object getFieldValue​(java.lang.Object bean,
                                                     java.lang.String fieldName)
                                              throws java.lang.IllegalAccessException
        Returns the value of a (nested) field on a bean. Intended for testing.
        Parameters:
        bean - the object
        fieldName - the field name, with "." separating nested properties
        Returns:
        the value of the nested field
        Throws:
        java.lang.IllegalAccessException
      • getProtectedFieldValue

        public static java.lang.Object getProtectedFieldValue​(java.lang.String protectedField,
                                                              java.lang.Object object)
      • setProtectedFieldValue

        public static void setProtectedFieldValue​(java.lang.String protectedField,
                                                  java.lang.Object object,
                                                  java.lang.Object newValue)