com.example.howtodoinjava.dozer.mode" /> com.example.howtodoinjava.dozer.mode" /> com.example.howtodoinjava.dozer.mode"/>

How to avoid dozer mapping blank strings in spring boot java app?

372 Views Asked by At

Consider the following xml dozer bean mapping below:

   <mapping map-null="false" map-empty-string="false">
        <class-a>com.example.howtodoinjava.dozer.models.Student</class-a>
        <class-b>com.example.howtodoinjava.dozer.models.StudentVO</class-b>
        <field>
            <a>batch</a>
            <b>batchName</b>
        </field>
        <field>
            <a>address</a>
            <b>homeAddress</b>
        </field>
    </mapping>
</mappings>

In the above dozer xml mapping, how to avoid map batch to batchName when batch is blank (" ")?

1

There are 1 best solutions below

2
John Camerin On BEST ANSWER

The Dozer documentation is your friend: https://dozermapper.github.io/gitbook/documentation/xmlConfiguration.html

Add trim-strings="true" to the mapping.

During the mapping of the field, String.trim() will be called on the source field value to "convert" it to the destination. This in combination with the skip empty strings already in the mapping perform as desired.