- 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 TypeMethodDescriptionClass<?> dtoClass()Retrieves the parentClassof the DTO containing the field targeted by thisFieldAccessor.default Class<?> Retrieves the single generic type associated with the field or property represented by thisFieldAccessor.Class<?>[]Returns an array ofClassobjects representing the generic types associated with the field or property represented by thisFieldAccessor.@Nullable ObjectRetrieve the value of a field or property from the provided data transfer object (DTO).name()Return the name of the field or property represented by thisFieldAccessor.voidSet the value of a field or property for the provided data transfer object (DTO).Class<?> type()Returns the declared type for the field represented by thisFieldAccessor.
-
Method Details
-
name
String name()Return the name of the field or property represented by thisFieldAccessor.- Returns:
- the name of the field or property as a
String
-
type
Class<?> type()Returns the declared type for the field represented by thisFieldAccessor.- Returns:
- the field type
-
dtoClass
Class<?> dtoClass()Retrieves the parentClassof the DTO containing the field targeted by thisFieldAccessor.- Returns:
- The parent DTO type
-
get
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 thisFieldAccessor.- Returns:
- the value of the field or property, or
nullif the field value is null or could not be accessed.
-
set
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 thisFieldAccessor.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 ofClassobjects representing the generic types associated with the field or property represented by thisFieldAccessor.- Returns:
- an array of
Classobjects that represent the generic types of the field or property, or an empty array if the field or property does not use generics.
-
genericType
Retrieves the single generic type associated with the field or property represented by thisFieldAccessor.If the field or property has more than one generic type or none at all, an
IllegalStateExceptionis thrown.- Returns:
- the
Classobject representing the single generic type of the field or property - Throws:
IllegalStateException- if the number of generic types is not exactly one
-