我正在嘗試遷移使用dozer
到orika
的項目。如何配置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>
然後轉換對象時使用的azazaz:
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");
所以我的問題是:如何配置奧裏卡有這樣的mapId的東西?
我無法找到如何聲明地圖-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());