JAXB - representing an element as a boolean member?

Posted by Marcus on Stack Overflow See other posts from Stack Overflow or by Marcus
Published on 2010-04-19T14:22:35Z Indexed on 2010/04/19 14:23 UTC
Read the original article Hit count: 293

Filed under:
|
|

We have this XML:

  <Summary>
     <ValueA>xxx</ValueA>
     <ValueB/>
  </Summary>

<ValueB/> will never have any attributes or inner elements. It's a boolean type element - it exists (true) or it doesn't (false).

JAXB generated a Summary class with a String valueA member, which is good.

But for ValueB, JAXB generated a ValueB inner class and a corresponding member:

@XmlElement(name = "ValueB")
protected Summary.ValueB valueB;

But what I'd like is a boolean member and no inner class:

@XmlElement(name = "ValueB")
protected boolean valueB;

How can you do this?

I'm not looking to regenerate the classes, I'd like to just make the code change manually.

© Stack Overflow or respective owner

Related posts about java

Related posts about jaxb