abstract class BeanUtils
Static convenience methods for JavaBeans: for instantiating beans, checking bean property types, copying bean properties, etc.
Mainly for use within the framework, but to some degree also useful for application classes.
Author
Rod Johnson
Author
Juergen Hoeller
Author
Rob Harrop
Author
Sam Brannen
Author
Sebastien Deleuze
BeanUtils()
Static convenience methods for JavaBeans: for instantiating beans, checking bean property types, copying bean properties, etc. Mainly for use within the framework, but to some degree also useful for application classes. |
open static fun copyProperties(source: Any, target: Any): Unit
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 BeanWrapper. open static fun copyProperties(source: Any, target: Any, editable: Class<*>): Unit
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 BeanWrapper. open static fun copyProperties(source: Any, target: Any, vararg ignoreProperties: String): Unit
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 BeanWrapper. |
|
open static fun findDeclaredMethod(clazz: Class<*>, methodName: String, vararg paramTypes: Class<*>): Method
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 |
|
open static fun findDeclaredMethodWithMinimalParameters(clazz: Class<*>, methodName: String): Method
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 |
|
open static fun findEditorByConvention(targetType: Class<*>): PropertyEditor
Find a JavaBeans PropertyEditor following the 'Editor' suffix convention (e.g. "mypackage.MyDomainClass" -> "mypackage.MyDomainClassEditor"). Compatible to the standard JavaBeans convention as implemented by java.beans.PropertyEditorManager but isolated from the latter's registered default editors for primitive types. |
|
open static fun findMethod(clazz: Class<*>, methodName: String, vararg paramTypes: Class<*>): Method
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 |
|
open static fun findMethodWithMinimalParameters(clazz: Class<*>, methodName: String): Method
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 open static fun findMethodWithMinimalParameters(methods: Array<Method>, methodName: String): Method
Find a method with the given method name and minimal parameters (best case: none) in the given list of methods. |
|
open static fun <T : Any> findPrimaryConstructor(clazz: Class<T>): Constructor<T>
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 |
|
open static fun findPropertyForMethod(method: Method): PropertyDescriptoropen static fun findPropertyForMethod(method: Method, clazz: Class<*>): PropertyDescriptor
Find a JavaBeans |
|
open static fun findPropertyType(propertyName: String, vararg beanClasses: Class<*>): Class<*>
Determine the bean property type for the given property from the given classes/interfaces, if possible. |
|
open static fun getPropertyDescriptor(clazz: Class<*>, propertyName: String): PropertyDescriptor
Retrieve the JavaBeans |
|
open static fun getPropertyDescriptors(clazz: Class<*>): Array<PropertyDescriptor>
Retrieve the JavaBeans |
|
open static fun getWriteMethodParameter(pd: PropertyDescriptor): MethodParameter
Obtain a new MethodParameter object for the write method of the specified property. |
|
open static fun <T : Any> instantiate(clazz: Class<T>): T
Convenience method to instantiate a class using its no-arg constructor. |
|
open static fun <T : Any> instantiateClass(clazz: Class<T>): T
Instantiate a class using its no-arg constructor. Note that this method tries to set the constructor accessible if given a non-accessible (that is, non-public) constructor. open static fun <T : Any> instantiateClass(clazz: Class<*>, assignableTo: Class<T>): T
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. open static fun <T : Any> instantiateClass(ctor: Constructor<T>, vararg args: Any): T
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. |
|
open static fun isSimpleProperty(clazz: Class<*>): Boolean
Check if the given type represents a "simple" property: a primitive, a String or other CharSequence, a Number, a Date, a URI, a URL, a Locale, a Class, or a corresponding array. Used to determine properties to check for a "simple" dependency-check. |
|
open static fun isSimpleValueType(clazz: Class<*>): Boolean
Check if the given type represents a "simple" value type: a primitive, a String or other CharSequence, a Number, a Date, a URI, a URL, a Locale or a Class. |
|
open static fun resolveSignature(signature: String, clazz: Class<*>): Method
Parse a method signature in the form When not supplying an argument list ( Note then that If no method can be found, then |