简体   繁体   English

Jibx中空值的空标签

[英]empty tag for null value in Jibx

I would like to create an empty tag for one of my attribute when its value is null in JIBX. 当JIBX中的属性值为null时,我想为我的一个属性创建一个空标签。 Can some one please help me out? 有人可以帮帮我吗? Lets say i have an attribute called 可以说我有一个名为

private String webId

For the above attribute , there is no value coming from DB, so its always null but , its a mandatory tag to be displayed as part of my response , so i want to show an empty tag for this attribute as <webId/> . 对于上面的属性,没有值来自DB,因此它始终为null,但是其必填标记将作为我的响应的一部分显示,因此我想将此属性的空标记显示为<webId/> My mapping in binding file is 我在绑定文件中的映射是

 <value name="webId" field="webId" />

Please note: i don't want to manually set its value as empty string if its value is null ,like 请注意:如果它的值为null,我不想手动将其值设置为空字符串,例如

if(webId==null){
   productDetails.setWebId("");
}

You can initialize the value in your class to an empty string like : 您可以将类中的值初始化为一个空字符串,例如:

private String webId =  new String();

So when JiBX does marshal, the XML will have an empty tag for it. 因此,当JiBX进行封送处理时,XML将为其添加一个空标记。

I tested this and it works for me. 我对此进行了测试,它对我有用。

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

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