英文:
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>
但是这并没有按预期工作。是否有其他方法可以排除嵌套对象的字段?
英文:
According to this example you can do Deep Mapping with 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>
Similarly I want to exclude few nested objects and fields, and so I tried same way :
> <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>
But this is not working as expected. Is there any other way how to exclude nested Object's fields?
答案1
得分: 7
你可以按照以下方式排除嵌套对象:
<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>
英文:
You can exclude nested objects as follows :
> <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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论