Mainly for internal use within the framework, but to some degree also useful for application classes. Consider Apache Commons BeanUtils, BULL - Bean Utils Light Library, or similar third-party frameworks for more comprehensive bean utilities.
| Modifier and Type | Class and Description |
|---|---|
| private static class | BeanUtils.KotlinDelegate
Inner class to avoid a hard dependency on Kotlin at runtime. |
| Modifier and Type | Field and Description |
|---|---|
| private static final Map | |
| private static final ParameterNameDiscoverer | |
| private static final Set |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static void | copyProperties(Object
the source bean source, Object the target bean target)Copy the property values of the given source bean into the target bean. |
| public static void | copyProperties(Object
the source bean source, Object the target bean target, Class<?> the class (or interface) to restrict property setting to editable)Copy the property values of the given source bean into the given target bean, only setting properties defined in the given "editable" class (or interface). |
| public static void | copyProperties(Object
the source bean source, Object the target bean target, String... array of property names to ignore ignoreProperties)Copy the property values of the given source bean into the given target bean, ignoring the given "ignoreProperties". |
| private static void | copyProperties(Object
the source bean source, Object the target bean target, Class<?> the class (or interface) to restrict property setting to editable, String... array of property names to ignore ignoreProperties)Copy the property values of the given source bean into the given target bean. |
| public static Method | Returns: the Method object, ornull if not foundthe class to check clazz, String the name of the method to find methodName, Class<?>... the parameter types of the method to find paramTypes)Find a method with the given method name and the given parameter types, declared on the given class or one of its superclasses. |
| public static Method | Returns: the Method object, ornull if not foundthe class to check clazz, String the name of the method to find methodName)Find a method with the given method name and minimal parameters (best case: none), declared on the given class or one of its superclasses. |
| public static PropertyEditor | Returns: the corresponding editor, ornull if none foundthe type to find an editor for targetType)Find a JavaBeans PropertyEditor following the 'Editor' suffix convention (e.g. "mypackage.MyDomainClass" → "mypackage.MyDomainClassEditor"). |
| public static Method | Returns: the Method object, ornull if not foundthe class to check clazz, String the name of the method to find methodName, Class<?>... the parameter types of the method to find paramTypes)Find a method with the given method name and the given parameter types, declared on the given class or one of its superclasses. |
| public static Method | Returns: the Method object, ornull if not foundthe class to check clazz, String the name of the method to find methodName)Find a method with the given method name and minimal parameters (best case: none), declared on the given class or one of its superclasses. |
| public static Method | Returns: the Method object, ornull if not foundthe methods to check methods, String the name of the method to find methodName)Find a method with the given method name and minimal parameters (best case: none) in the given list of methods. |
| public static <T> Constructor | findPrimaryConstructor(Class<T>
the class to check clazz)Return the primary constructor of the provided class. |
| public static PropertyDescriptor | Returns: the corresponding PropertyDescriptor, ornull if nonethe method to find a corresponding PropertyDescriptor for,
introspecting its declaring class method)Find a JavaBeans |
| public static PropertyDescriptor | Returns: the corresponding PropertyDescriptor, ornull if nonethe method to find a corresponding PropertyDescriptor for method, Class<?> the (most specific) class to introspect for descriptors clazz)Find a JavaBeans |
| public static Class | Returns: the property type, orObject.class as fallbackthe name of the bean property propertyName, Class<?>... the classes to check against beanClasses)Determine the bean property type for the given property from the given classes/interfaces, if possible. |
| public static String[] | Returns: the parameter names (matching the constructor's parameter count)the constructor to find parameter names for ctor)Determine required parameter names for the given constructor,
considering the JavaBeans |
| public static PropertyDescriptor | Returns: the corresponding PropertyDescriptor, ornull if nonethe Class to retrieve the PropertyDescriptor for clazz, String the name of the property propertyName)Retrieve the JavaBeans |
| public static PropertyDescriptor[] | Returns: an array ofPropertyDescriptors for the given classthe Class to retrieve the PropertyDescriptors for clazz)Retrieve the JavaBeans |
| public static <T> Constructor | getResolvableConstructor(Class<T>
the class to check clazz)Return a resolvable constructor for the provided class, either a primary or single public constructor with arguments, or a single non-public constructor with arguments, or simply a default constructor. |
| public static MethodParameter | Returns: a corresponding MethodParameter objectthe PropertyDescriptor for the property pd)Obtain a new MethodParameter object for the write method of the specified property. |
| public static boolean | Returns: true if writable and unique, false otherwisethe PropertyDescriptor for the property pd)Determine whether the specified property has a unique write method, i.e. is writable but does not declare overloaded setter methods. |
| public static <T> T | Returns: the new instanceclass to instantiate clazz)
Deprecated
as of Spring 5.0, following the deprecation of
Convenience method to instantiate a class using its no-arg constructor.
Class#newInstance() in JDK 9
|
| public static <T> T | Returns: the new instancethe class to instantiate clazz)Instantiate a class using its 'primary' constructor (for Kotlin classes, potentially having default arguments declared) or its default constructor (for regular Java classes, expecting a standard no-arg setup). |
| public static <T> T | Returns: the new instanceclass to instantiate clazz, Class<T> type that clazz must be assignableTo assignableTo)Instantiate a class using its no-arg constructor and return the new instance as the specified assignable type. |
| public static <T> T | Returns: the new instancethe constructor to instantiate ctor, Object... the constructor arguments to apply (use args)null for an unspecified
parameter, Kotlin optional parameters and Java primitive types are supported)Convenience method to instantiate a class using the given constructor. |
| private static boolean | isAssignable(Method writeMethod, Method readMethod, PropertyDescriptor sourcePd, PropertyDescriptor targetPd)
|
| public static boolean | Returns: whether the given type represents a "simple" propertythe type to check type)Check if the given type represents a "simple" property: a simple value type or an array of simple value types. |
| public static boolean | Returns: whether the given type represents a "simple" value typethe type to check type)Check if the given type represents a "simple" value type for
bean property and data binding purposes:
a primitive or primitive wrapper, an |
| public static Method | Returns: the resolved Methodthe method signature as String representation signature, Class<?> the class to resolve the method signature against clazz)Parse a method signature in the form |
| DEFAULT_TYPE_VALUES | back to summary |
|---|---|
| private static final Map<Class<?>, Object> DEFAULT_TYPE_VALUES | |
| parameterNameDiscoverer | back to summary |
|---|---|
| private static final ParameterNameDiscoverer parameterNameDiscoverer | |
| unknownEditorTypes | back to summary |
|---|---|
| private static final Set<Class<?>> unknownEditorTypes | |
| BeanUtils | back to summary |
|---|---|
| public BeanUtils() | |
| copyProperties | back to summary | |||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| public static void copyProperties(Object source, Object target) throws BeansException Copy the property values of the given source bean into the target bean. Note The source and target classes do not have to match or even be derived from each other, as long as the properties match. Any bean properties that the source bean exposes but the target bean does not will silently be ignored. This is just a convenience method. For more complex transfer needs,
consider using a full As of Spring Framework 5.3, this method honors generic type information when matching properties in the source and target objects. The following table provides a non-exhaustive set of examples of source and target property types that can be copied as well as source and target property types that cannot be copied.
| ||||||||||||||||||||||||||||||||||
| copyProperties | back to summary |
|---|---|
| public static void copyProperties(Object source, Object target, Class<?> editable) throws BeansException Copy the property values of the given source bean into the given target bean, only setting properties defined in the given "editable" class (or interface). Note The source and target classes do not have to match or even be derived from each other, as long as the properties match. Any bean properties that the source bean exposes but the target bean does not will silently be ignored. This is just a convenience method. For more complex transfer needs,
consider using a full As of Spring Framework 5.3, this method honors generic type information
when matching properties in the source and target objects. See the
documentation for
| |
| copyProperties | back to summary |
|---|---|
| public static void copyProperties(Object source, Object target, String... ignoreProperties) throws BeansException Copy the property values of the given source bean into the given target bean, ignoring the given "ignoreProperties". Note The source and target classes do not have to match or even be derived from each other, as long as the properties match. Any bean properties that the source bean exposes but the target bean does not will silently be ignored. This is just a convenience method. For more complex transfer needs,
consider using a full As of Spring Framework 5.3, this method honors generic type information
when matching properties in the source and target objects. See the
documentation for
| |
| copyProperties | back to summary |
|---|---|
| private static void copyProperties(Object source, Object target, Class<?> editable, String... ignoreProperties) throws BeansException Copy the property values of the given source bean into the given target bean. Note The source and target classes do not have to match or even be derived from each other, as long as the properties match. Any bean properties that the source bean exposes but the target bean does not will silently be ignored. As of Spring Framework 5.3, this method honors generic type information
when matching properties in the source and target objects. See the
documentation for
| |
| findDeclaredMethod | back to summary |
|---|---|
| public static Method findDeclaredMethod(Class<?> clazz, String methodName, Class<?>... paramTypes) Find a method with the given method name and the given parameter types, declared on the given class or one of its superclasses. Will return a public, protected, package access, or private method. Checks | |
| findDeclaredMethodWithMinimalParameters | back to summary |
|---|---|
| public static Method findDeclaredMethodWithMinimalParameters(Class<?> clazz, String methodName) throws IllegalArgumentException Find a method with the given method name and minimal parameters (best case: none), declared on the given class or one of its superclasses. Will return a public, protected, package access, or private method. Checks
| |
| findEditorByConvention | back to summary |
|---|---|
| public static PropertyEditor findEditorByConvention(Class<?> targetType) Find a JavaBeans PropertyEditor following the 'Editor' suffix convention (e.g. "mypackage.MyDomainClass" → "mypackage.MyDomainClassEditor"). Compatible to the standard JavaBeans convention as implemented by
| |
| findMethod | back to summary |
|---|---|
| public static Method findMethod(Class<?> clazz, String methodName, Class<?>... paramTypes) Find a method with the given method name and the given parameter types, declared on the given class or one of its superclasses. Prefers public methods, but will return a protected, package access, or private method too. Checks
| |
| findMethodWithMinimalParameters | back to summary |
|---|---|
| public static Method findMethodWithMinimalParameters(Class<?> clazz, String methodName) throws IllegalArgumentException Find a method with the given method name and minimal parameters (best case: none), declared on the given class or one of its superclasses. Prefers public methods, but will return a protected, package access, or private method too. Checks
| |
| findMethodWithMinimalParameters | back to summary |
|---|---|
| public static Method findMethodWithMinimalParameters(Method[] methods, String methodName) throws IllegalArgumentException Find a method with the given method name and minimal parameters (best case: none) in the given list of methods.
| |
| findPrimaryConstructor | back to summary |
|---|---|
| public static <T> Constructor Return the primary constructor of the provided class. For Kotlin classes, this
returns the Java constructor corresponding to the Kotlin primary constructor
(as defined in the Kotlin specification). Otherwise, in particular for non-Kotlin
classes, this simply returns
| |
| findPropertyForMethod | back to summary |
|---|---|
| public static PropertyDescriptor findPropertyForMethod(Method method) throws BeansException Find a JavaBeans
| |
| findPropertyForMethod | back to summary |
|---|---|
| public static PropertyDescriptor findPropertyForMethod(Method method, Class<?> clazz) throws BeansException Find a JavaBeans
| |
| findPropertyType | back to summary |
|---|---|
| public static Class Determine the bean property type for the given property from the given classes/interfaces, if possible. | |
| getParameterNames | back to summary |
|---|---|
| public static String[] getParameterNames(Constructor<?> ctor) Determine required parameter names for the given constructor,
considering the JavaBeans
| |
| getPropertyDescriptor | back to summary |
|---|---|
| public static PropertyDescriptor getPropertyDescriptor(Class<?> clazz, String propertyName) throws BeansException Retrieve the JavaBeans
| |
| getPropertyDescriptors | back to summary |
|---|---|
| public static PropertyDescriptor[] getPropertyDescriptors(Class<?> clazz) throws BeansException Retrieve the JavaBeans
| |
| getResolvableConstructor | back to summary |
|---|---|
| public static <T> Constructor Return a resolvable constructor for the provided class, either a primary or single public constructor with arguments, or a single non-public constructor with arguments, or simply a default constructor. Callers have to be prepared to resolve arguments for the returned constructor's parameters, if any.
| |
| getWriteMethodParameter | back to summary |
|---|---|
| public static MethodParameter getWriteMethodParameter(PropertyDescriptor pd) Obtain a new MethodParameter object for the write method of the specified property.
| |
| hasUniqueWriteMethod | back to summary |
|---|---|
| public static boolean hasUniqueWriteMethod(PropertyDescriptor pd) Determine whether the specified property has a unique write method, i.e. is writable but does not declare overloaded setter methods.
| |
| instantiate | back to summary |
|---|---|
| public static <T> T instantiate(Class<T> clazz) throws BeanInstantiationException
Deprecated as of Spring 5.0, following the deprecation of
Convenience method to instantiate a class using its no-arg constructor.
| |
| instantiateClass | back to summary |
|---|---|
| public static <T> T instantiateClass(Class<T> clazz) throws BeanInstantiationException Instantiate a class using its 'primary' constructor (for Kotlin classes, potentially having default arguments declared) or its default constructor (for regular Java classes, expecting a standard no-arg setup). Note that this method tries to set the constructor accessible if given a non-accessible (that is, non-public) constructor.
| |
| instantiateClass | back to summary |
|---|---|
| public static <T> T instantiateClass(Class<?> clazz, Class<T> assignableTo) throws BeanInstantiationException Instantiate a class using its no-arg constructor and return the new instance as the specified assignable type. Useful in cases where the type of the class to instantiate (clazz) is not available, but the type desired (assignableTo) is known. Note that this method tries to set the constructor accessible if given a non-accessible (that is, non-public) constructor.
| |
| instantiateClass | back to summary |
|---|---|
| public static <T> T instantiateClass(Constructor<T> ctor, Object... args) throws BeanInstantiationException Convenience method to instantiate a class using the given constructor. Note that this method tries to set the constructor accessible if given a non-accessible (that is, non-public) constructor, and supports Kotlin classes with optional parameters and default values.
| |
| isAssignable | back to summary |
|---|---|
| private static boolean isAssignable(Method writeMethod, Method readMethod, PropertyDescriptor sourcePd, PropertyDescriptor targetPd) | |
| isSimpleProperty | back to summary |
|---|---|
| public static boolean isSimpleProperty(Class<?> type) Check if the given type represents a "simple" property: a simple value type or an array of simple value types. See Used to determine properties to check for a "simple" dependency-check.
| |
| isSimpleValueType | back to summary |
|---|---|
| public static boolean isSimpleValueType(Class<?> type) Check if the given type represents a "simple" value type for
bean property and data binding purposes:
a primitive or primitive wrapper, an
As of 6.1, this method delegates to
| |
| resolveSignature | back to summary |
|---|---|
| public static Method resolveSignature(String signature, Class<?> clazz) Parse a method signature in the form When not supplying an argument list ( Note then that If no method can be found, then
| |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static <T> Constructor | findPrimaryConstructor(Class<T>
the clazz)Class of the Kotlin classRetrieve the Java constructor corresponding to the Kotlin primary constructor, if any. |
| public static <T> T | instantiateClass(Constructor<T>
the constructor of the Kotlin class to instantiate ctor, Object... the constructor arguments to apply
(use args)null for unspecified parameter if needed)Instantiate a Kotlin class using the provided constructor. |
| KotlinDelegate | back to summary |
|---|---|
| private KotlinDelegate() | |
| findPrimaryConstructor | back to summary |
|---|---|
| public static <T> Constructor Retrieve the Java constructor corresponding to the Kotlin primary constructor, if any.
| |
| instantiateClass | back to summary |
|---|---|
| public static <T> T instantiateClass(Constructor<T> ctor, Object... args) throws IllegalAccessException, InvocationTargetException, InstantiationException Instantiate a Kotlin class using the provided constructor.
| |