简体   繁体   中英

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

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.

I tested this and it works for me.

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