Class AnnotationDetectionFieldCallback

java.lang.Object
org.springframework.data.util.AnnotationDetectionFieldCallback
All Implemented Interfaces:
org.springframework.util.ReflectionUtils.FieldCallback

public class AnnotationDetectionFieldCallback extends Object implements org.springframework.util.ReflectionUtils.FieldCallback
A ReflectionUtils.FieldCallback that will inspect each field for a given annotation. This field's type can then be accessed afterwards.
Author:
Oliver Gierke, Christoph Strobl, Mark Paluch, Johannes Englmeier
  • Constructor Details

    • AnnotationDetectionFieldCallback

      public AnnotationDetectionFieldCallback(Class<? extends Annotation> annotationType)
      Creates a new AnnotationDetectionFieldCallback scanning for an annotation of the given type.
      Parameters:
      annotationType - must not be null.
  • Method Details

    • doWith

      public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException
      Specified by:
      doWith in interface org.springframework.util.ReflectionUtils.FieldCallback
      Throws:
      IllegalArgumentException
      IllegalAccessException
    • getField

      @Nullable public Field getField()
      Returns the detected field.
      Returns:
      the field
    • getRequiredField

      public Field getRequiredField()
      Returns the field that was detected.
      Returns:
      Throws:
      IllegalStateException - in case no field with the configured annotation was found.
    • getType

      @Nullable public Class<?> getType()
      Returns the type of the field.
      Returns:
    • getRequiredType

      public Class<?> getRequiredType()
      Returns the type of the field or throws an IllegalArgumentException if no field could be found.
      Returns:
      Throws:
      IllegalStateException - in case no field with the configured annotation was found.
    • getValue

      @Nullable public <T> T getValue(Object source)
      Retrieves the value of the field by reflection.
      Parameters:
      source - must not be null.
      Returns: