Package io.micronaut.core.beans
Interface BeanWrapper<T>
-
- Type Parameters:
T- The bean type.
- All Superinterfaces:
AnnotationMetadataProvider,AnnotationSource
public interface BeanWrapper<T> extends AnnotationMetadataProvider
Wraps a bean allowing to read and write its properties via a underlyingBeanIntrospection.- Since:
- 1.1
-
-
Field Summary
-
Fields inherited from interface io.micronaut.core.annotation.AnnotationSource
EMPTY
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static <T2> java.util.Optional<BeanWrapper<T2>>findWrapper(java.lang.Class<T2> type, T2 bean)Obtain a bean wrapper for the given bean.static <T2> java.util.Optional<BeanWrapper<T2>>findWrapper(T2 bean)Obtain a bean wrapper for the given bean.TgetBean()default java.util.Collection<BeanProperty<T,java.lang.Object>>getBeanProperties()The properties.BeanIntrospection<T>getIntrospection()default <P> java.util.Optional<P>getProperty(java.lang.String name, ArgumentConversionContext<P> context)Get the property of the given name and type.default <P> java.util.Optional<P>getProperty(java.lang.String name, Argument<P> type)Get the property of the given name and type.default <P> java.util.Optional<P>getProperty(java.lang.String name, java.lang.Class<P> type)Get the property of the given name and type.default java.lang.String[]getPropertyNames()The property names.default <P> PgetRequiredProperty(java.lang.String name, ArgumentConversionContext<P> context)Get the property value of the given type or throw an exception if it is unobtainable.default <P> PgetRequiredProperty(java.lang.String name, Argument<P> argument)Get the property value of the given type or throw an exception if it is unobtainable.default <P> PgetRequiredProperty(java.lang.String name, java.lang.Class<P> type)Get the property value of the given type or throw an exception if it is unobtainable.static <T2> BeanWrapper<T2>getWrapper(java.lang.Class<T2> type, T2 bean)Obtain a bean wrapper for the given bean.static <T2> BeanWrapper<T2>getWrapper(T2 bean)Obtain a bean wrapper for the given bean.default BeanWrapper<T>setProperty(java.lang.String name, java.lang.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, 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 Detail
-
getIntrospection
@NonNull BeanIntrospection<T> getIntrospection()
- Returns:
- The introspection.
-
getPropertyNames
@NonNull default java.lang.String[] getPropertyNames()
The property names.- Returns:
- The property names
-
getBeanProperties
@NonNull default java.util.Collection<BeanProperty<T,java.lang.Object>> getBeanProperties()
The properties.- Returns:
- The properties
-
getRequiredProperty
@NonNull default <P> P getRequiredProperty(@NonNull java.lang.String name, @NonNull java.lang.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 java.lang.String name, @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 java.lang.String name, @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> java.util.Optional<P> getProperty(@NonNull java.lang.String name, @NonNull java.lang.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
default <P> java.util.Optional<P> getProperty(@NonNull java.lang.String name, Argument<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
default <P> java.util.Optional<P> getProperty(@NonNull java.lang.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
default BeanWrapper<T> setProperty(@NonNull java.lang.String name, @Nullable java.lang.Object value)
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
@NonNull static <T2> BeanWrapper<T2> getWrapper(@NonNull T2 bean)
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> java.util.Optional<BeanWrapper<T2>> findWrapper(@NonNull T2 bean)
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> java.util.Optional<BeanWrapper<T2>> findWrapper(java.lang.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
@NonNull static <T2> BeanWrapper<T2> getWrapper(java.lang.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
-
-