我正在尝试迁移一个dozer
用于orika
.
在推土机中,有这样的东西是一种常见的做法:
<?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">
<mapping map-id="all">
<class-a>com.bnppa.cdj.dto.Source</class-a>
<class-b>com.bnppa.cdj.dto.Destination</class-b>
<field>
<a>id</a>
<b>id</b>
</field>
<field>
<a>someField</a>
<b>someField</b>
</field>
</mapping>
<mapping map-id="small">
<class-a>com.bnppa.cdj.dto.Source</class-a>
<class-b>com.bnppa.cdj.dto.Destination</class-b>
<field>
<a>id</a>
<b>id</b>
</field>
</mapping>
</mappings>
然后在转换对象时使用 mapId :
Source s = ...
List<String> mappingFiles = new ArrayList<String>();
mappingFiles.add("dozer/dozerMapping.xml");
mapper = new DozerBeanMapper(mappingFiles);
Destination d = mapper.map(mySource, Destination.class, "small");
所以我的问题是:如何配置 Orika 拥有这样的 mapId 东西?
当我定义我的映射器时,我找不到如何声明一个 map-id :
MapperFactory factory = new DefaultMapperFactory.Builder().build();
//Register a mapper
factory.registerClassMap(factory.classMap(Source.class, Destination.class)
.field("id","id")
.field("someField", "someField")
.toClassMap());