简体   繁体   English

推土机布尔映射-布尔值

[英]Dozer Boolean Mapping - Boolean Values

I am exposing a service that consumes another SOAP service. 我正在公开使用另一个SOAP服务的服务。 I was provided with a JAXB generated model of the service. 向我提供了JAXB生成的服务模型。 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. 我已经定义了自己的域模型,该域模型具有与JAXB模型完全相同的类集,但是没有xml注释等。我正在使用推土机执行数据映射。 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. 当某些标有注释(nillable = true)的布尔元素为null时,我的域模型中的目标对象Boolean对象将设置为默认true或false值。 I would like it to retain the same null value. 我希望它保留相同的null值。 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 JAXB模型

  @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. 这是因为JAXB会为布尔(对象)属性生成带有“ is”前缀的方法,而Dozer将为原始布尔类型使用“ is”前缀。 "Is-accessible" Dozer mapping configuration property should solve the problem. “可访问”的Dozer映射配置属性应解决该问题。 But it seems for some reason it has not. 但似乎出于某种原因却没有。 You could try: 您可以尝试:

rename property in domain model by removing "is" prefix 通过删除“ is”前缀在域模型中重命名属性

rename getters and setter in domain model to get/set 重命名域模型中的获取器和设置器以获取/设置

use "get-method" Dozer mapping configuration property to define get method of JAXB model 使用“ get-method”推土机映射配置属性来定义JAXB模型的get方法

use XJC plugin to fix get methods in JAXB model 使用XJC插件修复JAXB模型中的get方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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