简体   繁体   中英

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.

    // -----------------------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:

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

2. List fields containing custom object mappings:

This is explained at the below link: 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

Also, It will help to first write simple standalone programs to understand/test a particular mapping before jumping with implementation in your project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM