Search code examples
javajaxbdozer

Setting parent element to null which mapped child element is null - Dozer


I have generated classed using JAXB. It has generated lists for some of the complex elements. I have provided an example of class generated by JaxB -

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ArrayOfLineOfBusiness", propOrder = {
    "lineOfBusiness"
})
public class ArrayOfLineOfBusiness
    implements Serializable
{

    private final static long serialVersionUID = 11082011L;
    protected com.comcast.xml.epc.types.LineOfBusiness[] lineOfBusiness;
}

ArrayOfLineOfBusiness is used in Customer class

public class Customer{

@XmlElement(nillable = true)
protected ArrayOfLineOfBusiness linesOfBusiness;

My model class has something similar to below :

public class Customer implements Serializable {
private LineOfBusiness[] linesOfBusiness = null;

Below is my dozer mapping

<field>
    <a is-accessible="true">lineOfBusiness.lineOfBusinesses</a>
    <b>lineOfBusiness</b>
</field>

I want to set ArrayOfLineOfBusiness , if lineOfBusinesses array in my service model is null. Is there a way to do it?


Solution

  • The below mapping seems to address the scenario -

      <mapping map-null="false">