Friday, May 25, 2012

Navigating JAXB

Oh what a lot of time we've wasted on this...

We ran into the <... minOccurs="0" nillable="true"> minefield this week... We've a Java CXF client talking to a (by way of what's effectively a proxy) some services delivered from a third party. The WSDL exposed by the server we were talking to had minOccurs="0" nillable="true", the downstream service was insistent that we not send a tag if it was nil (using the XML serialisation), only of course by saying minOccurs="0" nillable="true" the server we were talking to allowed two representations and CXF/JAXB picked the wrong one.

So we fixed the WSDL (and then got all confused because no one had changed the embedded version...) and then started discovering all sorts of things we didn't know before!

Number one – if you've a JAXB binding file and are using generateElementProperty, it looks like it's Boolean, but actually it's tri-state... confused the ... out of us for a while – more details here.

Number two – if you've got an element you want to be nil, don't even initialise the member... if you're running with generateElementProperty absent or false, you'll get empty tags generated even where minOccurs="0", not initialising the member at all will omit the tag.


for IT the said...

I have read your blog its very attractive and impressive. I like it your blog.

Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

Java Online Training Java Online Training JavaEE Training in Chennai Java EE Training in Chennai

Travis Smith said...

Woah! I'm really enjoying the template/theme of this site. It's simple, yet effective. A lot of times it's challenging to get that "perfect balance" between user friendliness and visual appeal. I must say you have done a amazing job with this. In addition, the blog loads super quick for me on Chrome. Excellent Blog! all of craigslist