Package io.micronaut.core.beans
Interface BeanProperty<B,T>
- Type Parameters:
B
- The bean typeT
- The bean property type
- All Superinterfaces:
AnnotatedElement
,AnnotationMetadata
,AnnotationMetadataDelegate
,AnnotationMetadataProvider
,AnnotationSource
,ArgumentCoercible<T>
,BeanReadProperty<B,
,T> BeanWriteProperty<B,
,T> Named
- All Known Subinterfaces:
UnsafeBeanProperty<B,
T>
- All Known Implementing Classes:
AbstractBeanProperty
@NextMajorVersion("Remove all the methods, only keeping those in read/write interfaces")
public interface BeanProperty<B,T>
extends BeanReadProperty<B,T>, BeanWriteProperty<B,T>, ArgumentCoercible<T>
Represents a bean property and associated annotation metadata.
A BeanProperty
allows you to read the value of a property via get(Object)
or write to it via set(Object, Object)
, without using reflection.
The annotations of a property can be inspected via the AnnotationMetadataProvider.getAnnotationMetadata()
method.
- Since:
- 1.1
- Author:
- graemerocher
- See Also:
-
Field Summary
Fields inherited from interface io.micronaut.core.annotation.AnnotationMetadata
CLASS_NAME_SUFFIX, EMPTY_METADATA, VALUE_MEMBER
Fields inherited from interface io.micronaut.core.annotation.AnnotationSource
EMPTY
-
Method Summary
Modifier and TypeMethodDescriptionRepresent the type as an argument, including any generic type information.default void
convertAndSet
(B bean, @Nullable Object value) Convert the value and set if on the bean using the default conversion service.Read the bean value.default <T2> Optional<T2>
get
(B bean, @NonNull ArgumentConversionContext<T2> conversionContext) Read the value and try to convert it to the given type.default <T2> Optional<T2>
Read the value and try to convert it to the given type.Read the value and try to convert it to the given type.default <T2> T2
Read the value and try to convert it to the given type.The declaring type of the property.getType()
default boolean
This method returns true if the property can be mutated either via copy constructor or bean setter.default boolean
default boolean
Whether the property can be written to and read from.default boolean
default void
Write the bean value.default B
This method will attempt to modify the property or if this is an immutable type using a copy constructor to return a new instance with the new value.Methods inherited from interface io.micronaut.core.annotation.AnnotatedElement
isDeclaredNonNull, isDeclaredNullable, isNonNull, isNullable
Methods inherited from interface io.micronaut.core.annotation.AnnotationMetadata
enumValuesSet, enumValuesSet, getValues, hasDeclaredStereotype, hasEvaluatedExpressions, hasStereotypeNonRepeating, isAnnotationPresent, isDeclaredAnnotationPresent
Methods inherited from interface io.micronaut.core.annotation.AnnotationMetadataDelegate
booleanValue, booleanValue, booleanValue, booleanValue, classValue, classValue, classValue, classValue, classValues, classValues, classValues, classValues, copyAnnotationMetadata, doubleValue, doubleValue, doubleValue, enumValue, enumValue, enumValue, enumValue, enumValues, enumValues, enumValues, enumValues, findAnnotation, findAnnotation, findDeclaredAnnotation, findDeclaredAnnotation, findRepeatableAnnotation, findRepeatableAnnotation, getAnnotation, getAnnotation, getAnnotationNameByStereotype, getAnnotationNameByStereotype, getAnnotationNames, getAnnotationNamesByStereotype, getAnnotationNamesByStereotype, getAnnotationType, getAnnotationType, getAnnotationTypeByStereotype, getAnnotationTypeByStereotype, getAnnotationTypesByStereotype, getAnnotationTypesByStereotype, getAnnotationTypesByStereotype, getAnnotationValuesByName, getAnnotationValuesByStereotype, getAnnotationValuesByType, getDeclaredAnnotation, getDeclaredAnnotation, getDeclaredAnnotationNameByStereotype, getDeclaredAnnotationNames, getDeclaredAnnotationNamesByStereotype, getDeclaredAnnotationTypeByStereotype, getDeclaredAnnotationTypeByStereotype, getDeclaredAnnotationValuesByName, getDeclaredAnnotationValuesByType, getDeclaredMetadata, getDeclaredStereotypeAnnotationNames, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValues, getStereotypeAnnotationNames, getTargetAnnotationMetadata, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValues, getValues, hasAnnotation, hasAnnotation, hasDeclaredAnnotation, hasDeclaredAnnotation, hasDeclaredStereotype, hasDeclaredStereotype, hasDeclaredStereotype, hasPropertyExpressions, hasSimpleAnnotation, hasSimpleDeclaredAnnotation, hasStereotype, hasStereotype, hasStereotype, hasStereotype, intValue, intValue, intValue, isAnnotationPresent, isDeclaredAnnotationPresent, isEmpty, isFalse, isFalse, isPresent, isPresent, isRepeatableAnnotation, isRepeatableAnnotation, isTrue, isTrue, longValue, longValue, stringValue, stringValue, stringValue, stringValue, stringValues, stringValues, stringValues, stringValues, synthesize, synthesize, synthesizeAll, synthesizeAnnotationsByType, synthesizeDeclared, synthesizeDeclared, synthesizeDeclared, synthesizeDeclaredAnnotationsByType
Methods inherited from interface io.micronaut.core.annotation.AnnotationMetadataProvider
getAnnotationMetadata
-
Method Details
-
getDeclaringBean
- Specified by:
getDeclaringBean
in interfaceBeanReadProperty<B,
T> - Specified by:
getDeclaringBean
in interfaceBeanWriteProperty<B,
T> - Returns:
- The declaring bean introspection.
-
get
Read the bean value.- Specified by:
get
in interfaceBeanReadProperty<B,
T> - Parameters:
bean
- The bean to read from- Returns:
- The value
- Throws:
IllegalArgumentException
- If the bean instance if not of the correct type
-
get
Read the value and try to convert it to the given type.- Specified by:
get
in interfaceBeanReadProperty<B,
T> - Type Parameters:
T2
- The generic type- Parameters:
bean
- The beantype
- The type- Returns:
- The value if conversion was possible.
-
get
Read the value and try to convert it to the given type.- Specified by:
get
in interfaceBeanReadProperty<B,
T> - Type Parameters:
T2
- The generic type- Parameters:
bean
- The beanargument
- The type- Returns:
- The value if conversion was possible.
-
get
default <T2> Optional<T2> get(@NonNull B bean, @NonNull @NonNull ArgumentConversionContext<T2> conversionContext) Read the value and try to convert it to the given type.- Specified by:
get
in interfaceBeanReadProperty<B,
T> - Type Parameters:
T2
- The generic type- Parameters:
bean
- The beanconversionContext
- The conversion context to use- Returns:
- The value if conversion was possible.
-
get
@Nullable default <T2> T2 get(@NonNull B bean, @NonNull @NonNull Class<T2> type, @Nullable T2 defaultValue) Read the value and try to convert it to the given type.- Specified by:
get
in interfaceBeanReadProperty<B,
T> - Type Parameters:
T2
- The generic type- Parameters:
bean
- The beantype
- The typedefaultValue
- The default value if conversion is not possible- Returns:
- The value if conversion was possible.
-
hasSetterOrConstructorArgument
default boolean hasSetterOrConstructorArgument()This method returns true if the property can be mutated either via copy constructor or bean setter.- Returns:
- True if it is mutable
- Since:
- 2.3.0
- See Also:
-
withValue
This method will attempt to modify the property or if this is an immutable type using a copy constructor to return a new instance with the new value.This differs from
set(Object, Object)
which will throw an exception if the property does not have a setter.- If the property is read-only but can be provided via constructor argument a new instance representing a copy of the bean is returned.
- If the property is mutable then the passed instance is returned and
set(Object, Object)
invoked to mutate the property - If there is no way for the property to be mutated then an
UnsupportedOperationException
is thrown
- Specified by:
withValue
in interfaceBeanWriteProperty<B,
T> - Parameters:
bean
- The beanvalue
- The new value- Returns:
- Either the existing instance or the property is mutable or a newly created instance via the copy constructor pattern.
- Throws:
UnsupportedOperationException
- if the property cannot be mutated- Since:
- 2.3.0
-
set
Write the bean value.- Specified by:
set
in interfaceBeanWriteProperty<B,
T> - Parameters:
bean
- The beanvalue
- The value to write- Throws:
IllegalArgumentException
- If either the bean type or value type are not correct
-
convertAndSet
Convert the value and set if on the bean using the default conversion service.- Specified by:
convertAndSet
in interfaceBeanWriteProperty<B,
T> - Parameters:
bean
- The beanvalue
- The value- Throws:
ConversionErrorException
- If the value couldn't be converted
-
getType
- Specified by:
getType
in interfaceBeanReadProperty<B,
T> - Specified by:
getType
in interfaceBeanWriteProperty<B,
T> - Returns:
- The property type.
-
asArgument
Represent the type as an argument, including any generic type information.- Specified by:
asArgument
in interfaceArgumentCoercible<B>
- Specified by:
asArgument
in interfaceBeanReadProperty<B,
T> - Specified by:
asArgument
in interfaceBeanWriteProperty<B,
T> - Returns:
- The argument
-
isReadOnly
default boolean isReadOnly()- Returns:
- Whether the property is read-only
-
isWriteOnly
default boolean isWriteOnly()- Returns:
- Whether the property is write-only
-
isReadWrite
default boolean isReadWrite()Whether the property can be written to and read from.- Returns:
- True if it can.
-
getDeclaringType
The declaring type of the property.- Specified by:
getDeclaringType
in interfaceBeanReadProperty<B,
T> - Specified by:
getDeclaringType
in interfaceBeanWriteProperty<B,
T> - Returns:
- The type
-