Custom get() set() Methods

Mapping a field with no get() or set() methods

Use the attribute is-accessible to declare that the field can be accessed directly. Dozer is able to access private properties that do not have getter or setter methods.

    <b is-accessible="true">fieldAccessible</b>

Custom Set() and Get() methods (bi-directional)

For those beans that might have unorthodox getter and setter methods, Dozer support user specified setter and getter methods. To make a bi-directional mapping in this case, look at the following example below. The source field in element A specifies a custom setter method and getter method using attributes.

    <a set-method="placeValue" get-method="buildValue">value</a>

In this case we are mapping a String to an ArrayList by calling the addIntegerToList() method. Note that this is defined as a one-way field type since we can not map an ArrayList to a String.

<!-- we can not map a ArrayList to a String, hence the one-way mapping -->
<field type="one-way">
    <b set-method="addIntegerToList">integerList</b>

Overloaded Set() methods (bi-directional)

Sometimes set() methods can be overloaded. In order to chose the correct one you can add the class type as a parameter.

    <b set-method="setOverloadSetField(java.util.Date)">

Iterate Method Mapping (bi-directional)

Dozer also supports iterate method level mapping. In the following example the List appleComputers will be iterated through and for each object the method addComptuer will be called. Any field that is denoted as type=iterate requires a hint. The get() method can return an Array, List, or Iterator.

    <b set-method="addComputer" type="iterate">computers</b>

Below is an example with iterate methods on both fields.

    <a set-method="addCar" get-method="myIterateCars" type="iterate">iterateCars</a>
    <b set-method="addIterateCar" type="iterate">iterateCars</b>

results matching ""

    No results matching ""