Class FieldInfo

java.lang.Object
com.google.api.client.util.FieldInfo

public class FieldInfo extends Object
Parses field information to determine data key name/value pair associated with the field.

Implementation is thread-safe.

Since:
1.0
Author:
Yaniv Inbar
  • Method Details

    • of

      public static FieldInfo of(Enum<?> enumValue)
      Returns the field information for the given enum value.
      Parameters:
      enumValue - enum value
      Returns:
      field information
      Throws:
      IllegalArgumentException - if the enum value has no value annotation
      Since:
      1.4
    • of

      public static FieldInfo of(Field field)
      Returns the field information for the given field.
      Parameters:
      field - field or null for null result
      Returns:
      field information or null if the field has no name or for null input
    • getField

      public Field getField()
      Returns the field.
      Since:
      1.4
    • getName

      public String getName()
      Returns the data key name associated with the field for a non-enum-constant with a Key annotation, or data key value associated with the enum constant with a Value annotation or null for an enum constant with a NullValue annotation.

      This string is interned.

      Since:
      1.4
    • getType

      public Class<?> getType()
      Returns the field's type.
      Since:
      1.4
    • getGenericType

      public Type getGenericType()
      Returns the field's generic type, which is a class, parameterized type, generic array type, or type variable, but not a wildcard type.
      Since:
      1.4
    • isFinal

      public boolean isFinal()
      Returns whether the field is final.
      Since:
      1.4
    • isPrimitive

      public boolean isPrimitive()
      Returns whether the field is primitive as defined by Data.isPrimitive(Type).
      Since:
      1.4
    • getValue

      public Object getValue(Object obj)
      Returns the value of the field in the given object instance using reflection.
    • setValue

      public void setValue(Object obj, Object value)
      Sets this field in the given object to the given value using reflection.

      If the field is final, it checks that the value being set is identical to the existing value.

    • getClassInfo

      public ClassInfo getClassInfo()
      Returns the class information of the field's declaring class.
    • enumValue

      public <T extends Enum<T>> T enumValue()
    • getFieldValue

      public static Object getFieldValue(Field field, Object obj)
      Returns the value of the given field in the given object using reflection.
    • setFieldValue

      public static void setFieldValue(Field field, Object obj, Object value)
      Sets the given field in the given object to the given value using reflection.

      If the field is final, it checks that the value being set is identical to the existing value.