Package io.micronaut.core.beans
Interface BeanWrapper<T>
- Type Parameters:
T
- The bean type.
- All Superinterfaces:
AnnotationMetadataProvider
,AnnotationSource
Wraps a bean allowing to read and write its properties via an underlying
BeanIntrospection
.- Since:
- 1.1
- Author:
- graemerocher
-
Field Summary
Fields inherited from interface io.micronaut.core.annotation.AnnotationSource
EMPTY
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T2> @NonNull Optional<BeanWrapper<T2>>
findWrapper
(Class<T2> type, T2 bean) Obtain a bean wrapper for the given bean.static <T2> @NonNull Optional<BeanWrapper<T2>>
findWrapper
(T2 bean) Obtain a bean wrapper for the given bean.getBean()
default @NonNull Collection<BeanProperty<T,
Object>> The properties.getProperty
(@NonNull String name, @NonNull Class<P> type) Get the property of the given name and type.default <P> Optional<P>
getProperty
(@NonNull String name, ArgumentConversionContext<P> context) Get the property of the given name and type.default <P> Optional<P>
getProperty
(@NonNull String name, Argument<P> type) Get the property of the given name and type.The property names.default <P> P
getRequiredProperty
(@NonNull String name, @NonNull ArgumentConversionContext<P> context) Get the property value of the given type or throw an exception if it is unobtainable.default <P> P
getRequiredProperty
(@NonNull String name, @NonNull Argument<P> argument) Get the property value of the given type or throw an exception if it is unobtainable.default <P> P
getRequiredProperty
(@NonNull String name, @NonNull Class<P> type) Get the property value of the given type or throw an exception if it is unobtainable.static <T2> @NonNull BeanWrapper<T2>
getWrapper
(Class<T2> type, T2 bean) Obtain a bean wrapper for the given bean.static <T2> @NonNull BeanWrapper<T2>
getWrapper
(T2 bean) Obtain a bean wrapper for the given bean.default BeanWrapper<T>
setProperty
(@NonNull String name, @Nullable Object value) Sets a property of the given name to the given value.Methods inherited from interface io.micronaut.core.annotation.AnnotationMetadataProvider
findAnnotation, findAnnotation, findDeclaredAnnotation, findDeclaredAnnotation, getAnnotationMetadata, getTargetAnnotationMetadata, isAnnotationPresent, isDeclaredAnnotationPresent, synthesize, synthesizeAll, synthesizeAnnotationsByType, synthesizeDeclared, synthesizeDeclared, synthesizeDeclaredAnnotationsByType
Methods inherited from interface io.micronaut.core.annotation.AnnotationSource
getAnnotation, getAnnotation, getDeclaredAnnotation, getDeclaredAnnotation, isAnnotationPresent, isDeclaredAnnotationPresent, synthesize, synthesizeDeclared
-
Method Details
-
getIntrospection
- Returns:
- The introspection.
-
getBean
- Returns:
- The bean;
-
getPropertyNames
The property names.- Returns:
- The property names
-
getBeanProperties
The properties.- Returns:
- The properties
-
getRequiredProperty
@NonNull default <P> P getRequiredProperty(@NonNull @NonNull String name, @NonNull @NonNull Class<P> type) Get the property value of the given type or throw an exception if it is unobtainable.- Type Parameters:
P
- The property generic type- Parameters:
name
- The nametype
- The type- Returns:
- The property value
- Throws:
IntrospectionException
- if no property existsConversionErrorException
- if the property cannot be converted to the given type
-
getRequiredProperty
default <P> P getRequiredProperty(@NonNull @NonNull String name, @NonNull @NonNull Argument<P> argument) Get the property value of the given type or throw an exception if it is unobtainable.- Type Parameters:
P
- The property generic type- Parameters:
name
- The nameargument
- The argument type- Returns:
- The property value
- Throws:
IntrospectionException
- if no property existsConversionErrorException
- if the property cannot be converted to the given type
-
getRequiredProperty
@NonNull default <P> P getRequiredProperty(@NonNull @NonNull String name, @NonNull @NonNull ArgumentConversionContext<P> context) Get the property value of the given type or throw an exception if it is unobtainable.- Type Parameters:
P
- The property generic type- Parameters:
name
- The namecontext
- The type- Returns:
- The property value
- Throws:
IntrospectionException
- if no property existsConversionErrorException
- if the property cannot be converted to the given type
-
getProperty
@NonNull default <P> @NonNull Optional<P> getProperty(@NonNull @NonNull String name, @NonNull @NonNull Class<P> type) Get the property of the given name and type.- Type Parameters:
P
- The required generic type- Parameters:
name
- The nametype
- The required type- Returns:
- The property if found and can be converted to the given type
-
getProperty
Get the property of the given name and type.- Type Parameters:
P
- The required generic type- Parameters:
name
- The nametype
- The required type- Returns:
- The property if found and can be converted to the given type
-
getProperty
default <P> Optional<P> getProperty(@NonNull @NonNull String name, ArgumentConversionContext<P> context) Get the property of the given name and type.- Type Parameters:
P
- The required generic type- Parameters:
name
- The namecontext
- The conversion context- Returns:
- The property if found and can be converted to the given type
-
setProperty
Sets a property of the given name to the given value.- Parameters:
name
- The namevalue
- The value- Returns:
- This wrapper
- Throws:
ConversionErrorException
- if the value cannot be converted to the underlying property type.
-
getWrapper
Obtain a bean wrapper for the given bean.- Type Parameters:
T2
- The bean type- Parameters:
bean
- The bean- Returns:
- The wrapper
- Throws:
IntrospectionException
- If the wrapper cannot be created
-
findWrapper
Obtain a bean wrapper for the given bean.- Type Parameters:
T2
- The bean type- Parameters:
bean
- The bean- Returns:
- The wrapper
- Throws:
IntrospectionException
- If the wrapper cannot be created
-
findWrapper
@NonNull static <T2> @NonNull Optional<BeanWrapper<T2>> findWrapper(Class<T2> type, @NonNull T2 bean) Obtain a bean wrapper for the given bean.- Type Parameters:
T2
- The bean type- Parameters:
type
- the typebean
- The bean- Returns:
- The wrapper
- Throws:
IntrospectionException
- If the wrapper cannot be created
-
getWrapper
Obtain a bean wrapper for the given bean.- Type Parameters:
T2
- The bean type- Parameters:
type
- the typebean
- The bean- Returns:
- The wrapper
- Throws:
IntrospectionException
- If the wrapper cannot be created
-