[英]Complex POJO mapping using Dozer
I am new to Dozer, and have done flat mapping from one POJO to another using Dozer xml mapping.But now I want to map complex POJO which is given below and I am stucked how to do it. 我是Dozer的新手,并且已经使用Dozer xml映射完成了从一个POJO到另一个POJO的平面映射,但是现在我想映射下面给出的复杂POJO,我被困在如何做到这一点。
// -----------------------Source Classes-----------------------------
public class Source{
public String sourceId;
public Product product;
public List<Item> items;
}
public class Product{
public Integer productId;
public String productName;
}
public class Item{
public Integer id;
public Integer qty;
public String desc;
}
// -----------------------Destination Classes-------------------
public class Destination{
public String destId;
public DestProduct destProduct;
public List<DestItem> destItems;
}
public class DestProduct{
public Integer nProductId;
public String sProductName;
}
public class DestItem{
public Integer nId;
public Integer nQty;
public String sDesc;
}
How do I tell Dozer to map Source to Destination? 如何告诉推土机将“源”映射到“目标”?
You should check Dozer documentation. 您应该检查推土机文档。 It has everything you need to map your classes.
它具有映射类所需的一切。
I think you are worried mainly for below mappings: 我认为您主要担心以下映射:
1. Map custom object fields and wrapper classes fields: 1.映射自定义对象字段和包装器类字段:
Check the Basic property mapping in dozer documentation. 检查推土机文档中的基本属性映射 。 Many data type coversions are performed automatically by the Dozer mapping engine.
推土机映射引擎会自动执行许多数据类型转换。 Check the below link for more info.
检查以下链接以获取更多信息。 http://dozer.sourceforge.net/documentation/simpleproperty.html
http://dozer.sourceforge.net/documentation/simpleproperty.html
2. List fields containing custom object mappings: 2.列出包含自定义对象映射的字段:
This is explained at the below link: http://dozer.sourceforge.net/documentation/collectionandarraymapping.html# 在以下链接中对此进行了解释: http : //dozer.sourceforge.net/documentation/collectionandarraymapping.html#
For cases where a feature isn't supported out of the box, you can also write a custom converter: http://dozer.sourceforge.net/documentation/customconverter.html 对于开箱即用的功能不支持的情况,您还可以编写自定义转换器: http : //dozer.sourceforge.net/documentation/customconverter.html
Also, It will help to first write simple standalone programs to understand/test a particular mapping before jumping with implementation in your project. 此外,在跳转到项目中的实现之前,它首先有助于编写简单的独立程序以了解/测试特定的映射。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.