推土机 - 排除嵌套对象
Dozer - Excluding nested Objects
根据此示例,您可以使用 Dozer 进行深度映射:
http://dozer.sourceforge.net/documentation/deepmapping.html
<mapping>
<class-a>com.github.dozermapper.core.vo.deep.SrcDeepObj</class-a>
<class-b>com.github.dozermapper.core.vo.deep.DestDeepObj</class-b>
<field>
<a>srcNestedObj.src1</a>
<b>dest1</b>
</field>
<field>
<a>srcNestedObj.src2</a>
<b>dest2</b>
</field>
<field>
<a>srcNestedObj.srcNestedObj2.src5</a>
<b>dest5</b>
</field>
</mapping>
同样,我想排除一些嵌套对象和字段,所以我尝试了同样的方法:
<mapping map-id="case1" map-null="false">
<class-a>com.server.dal.entities.ClassA</class-a>
<class-b>com.server.dal.dto.ClassB</class-b>
<field-exclude>
<a>childObj1.childObj2</a>
<b>childObj1.childObj2</b>
</field-exclude>
<field-exclude>
<a>childObj1.childObj3.testMap</a>
<b>childObj1.childObj3.testMap</b>
</field-exclude>
</mapping>
但这没有按预期工作。有没有其他方法可以排除嵌套对象的字段?
您可以按如下方式排除嵌套对象:
<mapping map-id="caseClassA" map-null="false">
<class-a>com.server.dal.entities.ClassA</class-a>
<class-b>com.server.dal.dto.ClassB</class-b>
<field map-id="excludeSubItem1">
<a>childObj1</a>
<b>childObj1</b>
</field>
</mapping>
<mapping map-id="excludeSubitem1" map-null="false">
<class-a>com.server.dal.entities.ClassChild1</class-a>
<class-b>com.server.dal.dto.ClassChild1</class-b>
<field-exclude>
<a>childObj2</a>
<b>childObj2</b>
</field-exclude>
<field map-id="excludeSubItem2">
<a>childObj3</a>
<b>childObj3</b>
</field>
</mapping>
<mapping map-id="excludeSubitem2" map-null="false">
<class-a>com.server.dal.entities.ClassChild3</class-a>
<class-b>com.server.dal.dto.ClassChild3</class-b>
<field-exclude>
<a>testMap</a>
<b>testMap</b>
</field-exclude>
</mapping>
根据此示例,您可以使用 Dozer 进行深度映射:
http://dozer.sourceforge.net/documentation/deepmapping.html
<mapping> <class-a>com.github.dozermapper.core.vo.deep.SrcDeepObj</class-a> <class-b>com.github.dozermapper.core.vo.deep.DestDeepObj</class-b> <field> <a>srcNestedObj.src1</a> <b>dest1</b> </field> <field> <a>srcNestedObj.src2</a> <b>dest2</b> </field> <field> <a>srcNestedObj.srcNestedObj2.src5</a> <b>dest5</b> </field> </mapping>
同样,我想排除一些嵌套对象和字段,所以我尝试了同样的方法:
<mapping map-id="case1" map-null="false"> <class-a>com.server.dal.entities.ClassA</class-a> <class-b>com.server.dal.dto.ClassB</class-b> <field-exclude> <a>childObj1.childObj2</a> <b>childObj1.childObj2</b> </field-exclude> <field-exclude> <a>childObj1.childObj3.testMap</a> <b>childObj1.childObj3.testMap</b> </field-exclude> </mapping>
但这没有按预期工作。有没有其他方法可以排除嵌套对象的字段?
您可以按如下方式排除嵌套对象:
<mapping map-id="caseClassA" map-null="false"> <class-a>com.server.dal.entities.ClassA</class-a> <class-b>com.server.dal.dto.ClassB</class-b> <field map-id="excludeSubItem1"> <a>childObj1</a> <b>childObj1</b> </field> </mapping>
<mapping map-id="excludeSubitem1" map-null="false"> <class-a>com.server.dal.entities.ClassChild1</class-a> <class-b>com.server.dal.dto.ClassChild1</class-b> <field-exclude> <a>childObj2</a> <b>childObj2</b> </field-exclude> <field map-id="excludeSubItem2"> <a>childObj3</a> <b>childObj3</b> </field> </mapping>
<mapping map-id="excludeSubitem2" map-null="false"> <class-a>com.server.dal.entities.ClassChild3</class-a> <class-b>com.server.dal.dto.ClassChild3</class-b> <field-exclude> <a>testMap</a> <b>testMap</b> </field-exclude> </mapping>