Package com.jk.core.util
Class JKObjectUtil
java.lang.Object
com.jk.core.util.JKObjectUtil
The Class JKObjectUtil.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addItemToList
(Object target, String fieldName, Object value) Adds the item to list.static Object
callMethod
(Object obj, String methodName, boolean includePrivateMehtods, Object... args) Call method.static Object
callMethod
(Object obj, String methodName, Object... args) Call method.static Object
callStaticMethod
(Class clas, String methodName, Object... params) Call static method.static <T> T
Clone bean.static Object
Copy.static <T> T
createInstanceForGenericClass
(Object parent) Creates the instance for generic class.static com.fasterxml.jackson.databind.ObjectMapper
Creates the mapper.static com.fasterxml.jackson.databind.ObjectMapper
createMapper
(com.fasterxml.jackson.core.JsonFactory factory) Creates the mapper.static boolean
Equals.static Object
Evaluate.static String
fixPropertyName
(String name) Fix property name.getAllClassesInPackage
(String packageName) Gets the all classes in package.static <T> String[]
getAllFieldNames
(Class<T> modelClass) Gets the all field names.getAllFields
(Class<?> clas) Gets the all fields.static Class<?>
Gets the class.static Field
getFieldByName
(Class<?> classType, String name) Gets the field by name.static String
getFieldNameByType
(Class<?> classType, Class<?> fieldType) Gets the field name by type.static Object
getFieldValue
(Object instance, String fieldName) Gets the field value.static Class
getGenericClassFromParent
(Object parent) Gets the generic class from parent.static <T> Class<? extends T>
getGenericParamter
(String handler) Gets the generic paramter.static <T> String
getInstanceVariables
(Class<T> clas) Gets the instance variables.static Object
getPrivateValue
(Class<?> clas, Object instance, String fieldName) Gets the private value.static Object
getPrivateValue
(Object instance, String fieldName) Gets the private value.getProperties
(Class<T> clas) Gets the properties.static <T> T
getPropertyValue
(Object instance, String fieldName) Gets the property value.static Class<?>
getWrapperForPrimitive
(Class<?> clas) Gets the wrapper for primitive.static int
Hash.static boolean
Checks if is boolean.static boolean
isClassAvilableInClassPath
(String string) Checks if is class avilable in class path.static boolean
Checks if is date.static boolean
isFieldExists
(Class<?> clas, String fieldName) Checks if is field exists.static boolean
Checks if is final.static boolean
Checks if is integer.static boolean
isMethodDirectlyExists
(Object object, String methodName, Class<?>... params) Checks if is method directly exists.static boolean
isPrimitive
(Class<?> type) Checks if is primitive.static boolean
Checks if is static.static boolean
Checks if is time.static boolean
isTimeStamp
(Class type) Checks if is time stamp.static boolean
isTransient
(Field field) Checks if is transient.static <T> T
jsonToObject
(String json, Class<T> clas) Json to object.static <T> List<T>
jsonToObjectList
(String json, Class<T> clas) Json to object list.static <T> T
newInstance
(Class<T> clas) New instance.static <T> T
newInstance
(Class<T> clas, Object... params) New instance.static <T> T
newInstance
(String className) New instance.static void
Populate.static void
setPeopertyValue
(Object target, String fieldName, Object value) Sets the peoperty value.static void
setPropertiesByOrder
(Object model, String[] names, String[] values) Sets the properties by order.static Class<?>
To class.static Class<?>[]
toClassesFromObjects
(Object[] params) To classes from objects.static String
To json.static Object
To object.static String
To string.static String
To string.static String
To xml.static String
To yaml.static <T> T
yamlToObject
(String yaml, Class<T> clas) Yaml to object.
-
Constructor Details
-
JKObjectUtil
public JKObjectUtil()
-
-
Method Details
-
cloneBean
Clone bean.- Type Parameters:
T
- the generic type- Parameters:
bean
- the bean- Returns:
- the t
-
getClass
Gets the class.- Parameters:
beanClassName
- the bean class name- Returns:
- the class
-
getPropertyValue
Gets the property value.- Type Parameters:
T
- the generic type- Parameters:
instance
- the instancefieldName
- the field name- Returns:
- the property value
-
isBoolean
Checks if is boolean.- Parameters:
type
- the type- Returns:
- true, if is boolean
-
isDate
Checks if is date.- Parameters:
type
- the type- Returns:
- true, if is date
-
isFinal
Checks if is final.- Parameters:
field
- the field- Returns:
- true, if is final
-
isStatic
Checks if is static.- Parameters:
field
- the field- Returns:
- true, if is static
-
isTime
Checks if is time.- Parameters:
type
- the type- Returns:
- true, if is time
-
isTimeStamp
Checks if is time stamp.- Parameters:
type
- the type- Returns:
- true, if is time stamp
-
isTransient
Checks if is transient.- Parameters:
field
- the field- Returns:
- true, if is transient
-
newInstance
New instance.- Type Parameters:
T
- the generic type- Parameters:
clas
- the clas- Returns:
- the t
-
newInstance
New instance.- Type Parameters:
T
- the generic type- Parameters:
clas
- the clasparams
- the params- Returns:
- the t
-
newInstance
New instance.- Type Parameters:
T
- the generic type- Parameters:
className
- the class name- Returns:
- the t
-
setPeopertyValue
Sets the peoperty value.- Parameters:
target
- the targetfieldName
- the field namevalue
- the value
-
addItemToList
Adds the item to list.- Parameters:
target
- the targetfieldName
- the field namevalue
- the value
-
toClass
To class.- Parameters:
name
- the name- Returns:
- the class
-
toClassesFromObjects
To classes from objects.- Parameters:
params
- the params- Returns:
- the class[]
-
toString
To string.- Parameters:
object
- the objectuseCurrentTostringIfAvailable
- the use current tostring if available- Returns:
- the string
-
toString
To string.- Parameters:
object
- the object- Returns:
- the string
-
isMethodDirectlyExists
Checks if is method directly exists.- Parameters:
object
- the objectmethodName
- the method nameparams
- the params- Returns:
- true, if is method directly exists
-
equals
Equals.- Parameters:
source
- the sourcetarget
- the target- Returns:
- true, if successful
-
getFieldValue
Gets the field value.- Parameters:
instance
- the instancefieldName
- the field name- Returns:
- the field value
-
callStaticMethod
Call static method.- Parameters:
clas
- the clasmethodName
- the method nameparams
- the params- Returns:
- the object
-
copy
Copy.- Parameters:
source
- the source- Returns:
- the object
-
toXml
To xml.- Parameters:
obj
- the obj- Returns:
- the string
-
toObject
To object.- Parameters:
xml
- the xml- Returns:
- the object
-
hash
Hash.- Parameters:
name
- the name- Returns:
- the int
-
getGenericParamter
Gets the generic paramter.- Type Parameters:
T
- the generic type- Parameters:
handler
- the handler- Returns:
- the generic paramter
-
fixPropertyName
Fix property name.- Parameters:
name
- the name- Returns:
- the string
-
populate
Populate.- Parameters:
instance
- the instancevalues
- the values
-
isClassAvilableInClassPath
Checks if is class avilable in class path.- Parameters:
string
- the string- Returns:
- true, if is class avilable in class path
-
callMethod
public static Object callMethod(Object obj, String methodName, boolean includePrivateMehtods, Object... args) throws InvocationTargetException Call method.- Parameters:
obj
- the objmethodName
- the method nameincludePrivateMehtods
- the include private mehtodsargs
- the args- Returns:
- the object
- Throws:
InvocationTargetException
- the invocation target exception
-
callMethod
Call method.- Parameters:
obj
- the objmethodName
- the method nameargs
- the args- Returns:
- the object
-
getInstanceVariables
Gets the instance variables.- Type Parameters:
T
- the generic type- Parameters:
clas
- the clas- Returns:
- the instance variables
-
getProperties
Gets the properties.- Type Parameters:
T
- the generic type- Parameters:
clas
- the clas- Returns:
- the properties
-
toJson
To json.- Parameters:
obj
- the obj- Returns:
- the string
-
createMapper
public static com.fasterxml.jackson.databind.ObjectMapper createMapper()Creates the mapper.- Returns:
- the object mapper
-
createMapper
public static com.fasterxml.jackson.databind.ObjectMapper createMapper(com.fasterxml.jackson.core.JsonFactory factory) Creates the mapper.- Parameters:
factory
- the factory- Returns:
- the object mapper
-
toYaml
To yaml.- Parameters:
obj
- the obj- Returns:
- the string
-
jsonToObject
Json to object.- Type Parameters:
T
- the generic type- Parameters:
json
- the jsonclas
- the clas- Returns:
- the object
-
jsonToObjectList
Json to object list.- Type Parameters:
T
- the generic type- Parameters:
json
- the jsonclas
- the clas- Returns:
- the list
-
yamlToObject
Yaml to object.- Type Parameters:
T
- the generic type- Parameters:
yaml
- the yamlclas
- the clas- Returns:
- the object
-
getWrapperForPrimitive
Gets the wrapper for primitive.- Parameters:
clas
- the clas- Returns:
- the wrapper for primitive
-
isPrimitive
Checks if is primitive.- Parameters:
type
- the type- Returns:
- true, if is primitive
-
getFieldNameByType
Gets the field name by type.- Parameters:
classType
- the class typefieldType
- the field type- Returns:
- the field name by type
-
getFieldByName
Gets the field by name.- Parameters:
classType
- the class typename
- the name- Returns:
- the field by name
-
isInteger
Checks if is integer.- Parameters:
type
- the type- Returns:
- true, if is integer
-
isFieldExists
Checks if is field exists.- Parameters:
clas
- the clasfieldName
- the field name- Returns:
- true, if is field exists
-
getAllClassesInPackage
Gets the all classes in package.- Parameters:
packageName
- the package name- Returns:
- the all classes in package
-
getAllFields
Gets the all fields.- Parameters:
clas
- the clas- Returns:
- the all fields
-
createInstanceForGenericClass
Creates the instance for generic class.- Type Parameters:
T
- the generic type- Parameters:
parent
- the parent- Returns:
- the t
-
getGenericClassFromParent
Gets the generic class from parent.- Parameters:
parent
- the parent- Returns:
- the generic class from parent
-
getPrivateValue
Gets the private value.- Parameters:
instance
- the instancefieldName
- the field name- Returns:
- the private value
-
getPrivateValue
Gets the private value.- Parameters:
clas
- the clasinstance
- the instancefieldName
- the field name- Returns:
- the private value
-
evaluate
Evaluate.- Parameters:
rootObject
- the root objectvalueExpression
- the value expression- Returns:
- the object
-
setPropertiesByOrder
Sets the properties by order.- Parameters:
model
- the modelnames
- the namesvalues
- the values
-
getAllFieldNames
Gets the all field names.- Type Parameters:
T
- the generic type- Parameters:
modelClass
- the model class- Returns:
- the all field names
-