Mapping different property names (bidi)

21 views
Skip to first unread message

i...@gmx.at

unread,
Sep 14, 2016, 8:14:13 AM9/14/16
to Dozer Mapper
Two classes:

- MyEntity( id:int, uid:UUID, name:string)
- MyDomainEntity( id:UUID, name:string)

Map MyEntity to MyDomainEntity:
- (id >> null)
- uid >> id
- name >> name

Map MyDomainEntity to MyEntity
- (null >> id)
- id >> uid
- name >> name

How can this be done with dozer.

I get the following error:
org.apache.commons.beanutils.ConversionException: Error converting from 'UUID' to 'Integer' For input string: "7cc80b09-6e15-471f-900d-a5885832fe1d"

... with that configuration:
<?xml version="1.0" encoding="UTF-8"?>
<mappings xmlns="http://dozer.sourceforge.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://dozer.sourceforge.net
http://dozer.sourceforge.net/schema/beanmapping.xsd">

<configuration>
<stop-on-errors>true</stop-on-errors>
<date-format>MM/dd/yyyy HH:mm</date-format>
<wildcard>true</wildcard>
</configuration>

<mapping type="one-way">
<class-a>com.pmc.maventest2.dal.MyEntity</class-a>
<class-b>com.pmc.maventest2.dal.MyDomainEntity</class-b>
<field copy-by-reference="true">
<a>Uid</a>
<b>Id</b>
</field>
</mapping>

<mapping type="one-way">
<class-a>com.pmc.maventest2.dal.MyDomainEntity</class-a>
<class-b>com.pmc.maventest2.dal.MyEntity</class-b>
<field copy-by-reference="true">
<a>Id</a>
<b>UId</b>
</field>
</mapping>


</mappings>

i...@gmx.at

unread,
Sep 15, 2016, 5:45:23 AM9/15/16
to Dozer Mapper
Just found it out.
For that case this is the solution:

<mapping >
    <class-a>com.pmc.maventest2.dal.MyEntity</class-a>
<class-b>com.pmc.maventest2.dal.MyDomainEntity</class-b>
<field copy-by-reference="true">
<a>Uid</a>
<b>Id</b>
</field>
    <field-exclude>
<a>Id</a>
<b>Id</b>
</field-exclude>
</mapping>
Reply all
Reply to author
Forward
0 new messages