Package com.axelor.db.mapper
Class Mapper
java.lang.Object
com.axelor.db.mapper.Mapper
This class can be used to map params to Java bean using reflection. It also provides convenient
methods to get/set values to a bean instance.
-
Method Summary
Modifier and TypeMethodDescriptionGet the value of given property from the given bean.Class
<?> Get the bean class this mapper operates on.getComputeDependencies
(Property property) Find the fields directly accessed by the compute method of the given computed property.Get the getter method of the given property.Get the property of the name field.Property[]
Get all the properties.getProperty
(Object bean, String name) Get theProperty
orJsonProperty
of the given name if it exists.getProperty
(Method method) GetProperty
by it's getter, setter or compute method.getProperty
(String name) Get theProperty
of the given name.Property[]
Get all theSequence
fields.Get the setter method of the given property.static Mapper
Create aMapper
for the given Java Bean class by introspecting all it's properties.Set the property of the given bean with the provided value.static <T> T
Create an object of the given class mapping the given value map to it's properties.Create a map from the given bean instance with property names are keys and their respective values are map values.
-
Method Details
-
of
Create aMapper
for the given Java Bean class by introspecting all it's properties.If the
Mapper
class has been previously created for the given class, then theMapper
class is retrieved from the cache.- Parameters:
klass
- the bean class- Returns:
- an instance of
Mapper
for the given class.
-
getProperties
Get all the properties.- Returns:
- an array of
Property
-
getProperty
Get theProperty
of the given name.- Parameters:
name
- name of the property- Returns:
- a Property or null if property doesn't exist.
-
getProperty
Get theProperty
orJsonProperty
of the given name if it exists.- Parameters:
bean
- the beanname
- name of the property- Returns:
- a Property or null if property doesn't exist.
-
getProperty
GetProperty
by it's getter, setter or compute method.- Parameters:
method
- the getter, setter or compute method- Returns:
- the property associated with the method
-
getNameField
Get the property of the name field.A name field annotated with
NameColumn
or a field with namename
is considered name field.- Returns:
- a property
-
getSequenceFields
Get all theSequence
fields.- Returns:
- copy of the original set of fields.
-
getComputeDependencies
Find the fields directly accessed by the compute method of the given computed property.- Parameters:
property
- the computed property- Returns:
- set of fields accessed by computed property
-
getBeanClass
Get the bean class this mapper operates on.- Returns:
- the bean class
-
getGetter
Get the getter method of the given property.- Parameters:
name
- name of the property- Returns:
- getter method or null if property is write-only
-
getSetter
Get the setter method of the given property.- Parameters:
name
- name of the property- Returns:
- setter method or null if property is read-only
-
get
Get the value of given property from the given bean. It returnsnull
if property doesn't exist.- Parameters:
bean
- the beanname
- name of the property- Returns:
- property value
-
set
Set the property of the given bean with the provided value.- Parameters:
bean
- the beanname
- name of the propertyvalue
- value for the property- Returns:
- old value of the property
-
toBean
Create an object of the given class mapping the given value map to it's properties.- Type Parameters:
T
- type of the bean- Parameters:
klass
- class of the beanvalues
- value map- Returns:
- an instance of the given class
-
toMap
Create a map from the given bean instance with property names are keys and their respective values are map values.- Parameters:
bean
- a bean instance- Returns:
- a map
-