我在将简单的HashMap映射到嵌套的Hashmap时遇到了麻烦 我的简单源映射有一个sourceMapKey和一个sourceMapValue。该源映射应该映射到目标映射。目标映射应该以包含映射的sourceMapKey和sourceMapValue的targetSubMap结束,如下所示:
{targetSubMap={targetMapkey=sourceMapValue}}
我的代码如下所示:
HashMap<Object, Object> sourceMap = new HashMap<Object, Object>();
sourceMap.put("sourceMapKey", "sourceMapValue");
List<String> myMappingFiles = new ArrayList<String>();
myMappingFiles.add("file:\\C:\\mapping.xml");
DozerBeanMapper mapper = new DozerBeanMapper();
mapper.setMappingFiles(myMappingFiles);
HashMap<Object, Object> targetMap = mapper.map(sourceMap, HashMap.class, "MainMap");
我的mapping.xml如下所示:
<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="MainMap">
<class-a is-accessible="true">java.util.HashMap</class-a>
<class-b is-accessible="true">java.util.HashMap</class-b>
<field map-id="SubMap">
<a>this</a>
<b key="targetSubMap">this</b>
<a-hint>java.util.HashMap</a-hint>
<b-hint>java.util.HashMap</b-hint>
</field>
</mapping>
<mapping map-id="SubMap">
<class-a>java.util.HashMap</class-a>
<class-b>java.util.HashMap</class-b>
<field>
<a key="sourceMapKey">this</a>
<b key="targetMapKey">this</b>
<a-hint>java.util.HashMap</a-hint>
<b-hint>java.util.HashMap</b-hint>
</field>
</mapping>
</mappings>
我在目标地图中得到的结果是:
{targetSubMap=null}
我做错了什么?