Interface FieldAccessor

All Known Implementing Classes:
DirectFieldAccessor, FieldAccessorChain, PropertyAccessor

public interface FieldAccessor
Abstraction for accessing and manipulating fields or properties of a data transfer object (DTO).

Enables getting and setting field values, retrieving metadata about the field, such as its name, type, generic types, and declaring class.

  • Method Summary

    Modifier and Type
    Method
    Description
    Retrieves the parent Class of the DTO containing the field targeted by this FieldAccessor.
    default Class<?>
    Retrieves the single generic type associated with the field or property represented by this FieldAccessor.
    Class<?>[]
    Returns an array of Class objects representing the generic types associated with the field or property represented by this FieldAccessor.
    @Nullable Object
    get(Object dto)
    Retrieve the value of a field or property from the provided data transfer object (DTO).
    Return the name of the field or property represented by this FieldAccessor.
    void
    set(Object dto, @Nullable Object value)
    Set the value of a field or property for the provided data transfer object (DTO).
    Returns the declared type for the field represented by this FieldAccessor.
  • Method Details

    • name

      String name()
      Return the name of the field or property represented by this FieldAccessor.
      Returns:
      the name of the field or property as a String
    • type

      Class<?> type()
      Returns the declared type for the field represented by this FieldAccessor.
      Returns:
      the field type
    • dtoClass

      Class<?> dtoClass()
      Retrieves the parent Class of the DTO containing the field targeted by this FieldAccessor.
      Returns:
      The parent DTO type
    • get

      @Nullable Object get(Object dto)
      Retrieve the value of a field or property from the provided data transfer object (DTO).
      Parameters:
      dto - the data transfer object from which to retrieve the field or property value. Must not be null and should conform to the structure expected by this FieldAccessor.
      Returns:
      the value of the field or property, or null if the field value is null or could not be accessed.
    • set

      void set(Object dto, @Nullable Object value)
      Set the value of a field or property for the provided data transfer object (DTO).
      Parameters:
      dto - the data transfer object for which the field or property value will be set. Must not be null and should conform to the structure expected by this FieldAccessor.
      value - the value to set for the field or property. May be null if the field or property allows null values.
    • genericTypes

      Class<?>[] genericTypes()
      Returns an array of Class objects representing the generic types associated with the field or property represented by this FieldAccessor.
      Returns:
      an array of Class objects that represent the generic types of the field or property, or an empty array if the field or property does not use generics.
    • genericType

      default Class<?> genericType()
      Retrieves the single generic type associated with the field or property represented by this FieldAccessor.

      If the field or property has more than one generic type or none at all, an IllegalStateException is thrown.

      Returns:
      the Class object representing the single generic type of the field or property
      Throws:
      IllegalStateException - if the number of generic types is not exactly one