users@jaxb.java.net

Re: Marshal Empty Elements

From: Kohsuke Kawaguchi <kohsuke.kawaguchi_at_sun.com>
Date: Thu, 09 Jun 2005 18:52:31 -0400

Scott Kaszyk wrote:
> I have a schema that defines a mandatory element (minOcc=1, maxOcc=1). JAXB
> represents this element as a BigInteger type.
>
> When an empty element for this mandatory element is passed to the unmarshaller,
> it passes validation. However, I am not able to marshal back into an empty element.
>
> Does anyone know how to accomplish getting past the validator and marshalling an
> empty element?

Is that 1.0 or 2.0?

empty element for xs:decimal isn't a valid XML. Are you knowingly doing
this?

The validator is supposed to catch it as an error, so that sounds like a
bug.

And as long as it's bound to BigInteger, there's no way to print out an
empty element (after all, it's not a valid XML!).

If you really insist on generating an invalid XML, you can use
<javaType> customization to bind it to String. There's a sample in the
JAXB RI bundle that shows you how to use <javaType> customization.

-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com