简体   繁体   中英

Dozer Boolean Mapping - Boolean Values

I am exposing a service that consumes another SOAP service. I was provided with a JAXB generated model of the service. When I consume the service the data gets set into the objects pertinent to this model. I have defined my own domain model which has exactly the same set of classes as the JAXB model , but doesn't have the xml annotations etc. I am using dozer for performing the data mapping. When some of the boolean elements marked with annotation (nillable=true) are null , the destination object Boolean object in my domain model is set with default true or false value. I would like it to retain the same null value. The mapping and definition of boolean variables are listed below.

<mapping>
    <class-a>com.customer.types.CustomerPreferences
    </class-a>
    <class-b>com.customer.types.xml.CustomerPreferences
    </class-b>
    <field>
        <a is-accessible="true">isRequired</a>
        <b is-accessible="true">isRequired</b>
    </field>
</mapping>

JAXB Model

  @javax.xml.bind.annotation.XmlElement(nillable=true)
  protected java.lang.Boolean isRequired;
  // getters and setters

Domain Model

private Boolean isRequired;
//getters and setters

This is because JAXB generates methods with "is" prefix for Boolean (object) properties but Dozer uses "is" prefix for primitive boolean types. "Is-accessible" Dozer mapping configuration property should solve the problem. But it seems for some reason it has not. You could try:

rename property in domain model by removing "is" prefix

rename getters and setter in domain model to get/set

use "get-method" Dozer mapping configuration property to define get method of JAXB model

use XJC plugin to fix get methods in JAXB model

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