public class ObjectUtil extends Object
Constructor and Description |
---|
ObjectUtil() |
Modifier and Type | Method and Description |
---|---|
static <T> T |
convert(Object object,
Class<T> targetClass)
Converts the given object to the targetClass
|
static <T> T |
defaultIfNull(T value,
T defaultValue)
Return the defaultValue if the passed value is null.
|
static PropertyDescriptor[] |
getDescriptors(Class<?> targetClass) |
static Object |
getProperty(Object object,
String propertyName)
For a given object, try to find the appropriate reader method and return the value, if set
for the object.
|
static Class |
getPropertyType(Object object,
String propertyName)
Tried to determine the appropriate reader method for a given propertyName of a given object and, if found,
returns the class of its return type.
|
static boolean |
hasProperty(Object object,
String propertyName)
Examines the given object's class and returns true if reader and writer methods both exist for the
given property name.
|
static boolean |
hasReadProperty(Object object,
String propertyName)
Examines the given object's class and returns true if a reader method exists for the
given property name.
|
static boolean |
hasWriteProperty(Object object,
String propertyName)
Examines the given object's class and returns true if a writer method exists for the
given property name.
|
static void |
setProperty(Object object,
String propertyName,
Object propertyValue)
Sets the selected property of the given object to propertyValue.
|
static void |
setProperty(Object object,
String propertyName,
String propertyValue)
Tries to guess the "real" data type of propertyValue by the given propertyName, then sets the
selected property of the given object to that value.
|
public static Object getProperty(Object object, String propertyName) throws UnexpectedLiquibaseException
UnexpectedLiquibaseException
run-time exception occurs.object
- the object to examinepropertyName
- the property name for which the value should be readUnexpectedLiquibaseException
public static Class getPropertyType(Object object, String propertyName)
object
- the object to examinepropertyName
- the property name whose reading method should be searchedpublic static boolean hasProperty(Object object, String propertyName)
object
- the object for which the class should be examinedpropertyName
- the property name to searchpublic static boolean hasReadProperty(Object object, String propertyName)
object
- the object for which the class should be examinedpropertyName
- the property name to searchpublic static boolean hasWriteProperty(Object object, String propertyName)
object
- the object for which the class should be examinedpropertyName
- the property name to searchpublic static void setProperty(Object object, String propertyName, String propertyValue)
object
- the object whose property should be setpropertyName
- name of the property to setpropertyValue
- new value of the property, as Stringpublic static void setProperty(Object object, String propertyName, Object propertyValue)
object
- the object whose property should be setpropertyName
- name of the property to setpropertyValue
- new value of the propertypublic static <T> T convert(Object object, Class<T> targetClass) throws IllegalArgumentException
IllegalArgumentException
public static <T> T defaultIfNull(T value, T defaultValue)
public static PropertyDescriptor[] getDescriptors(Class<?> targetClass) throws IntrospectionException
IntrospectionException
Copyright © 2023 Liquibase.org. All rights reserved.