users@jaxb.java.net

Re: Strange output for nillable elements at marshall time

From: Pete Hendry <peter.hendry_at_capeclear.com>
Date: Sat, 30 Aug 2003 00:03:14 +1200

The output you propose is invalid. Your output defines a value of "".
This is not a valid date value and is not equivalent of java null
(schema nil). You have 2 choices:

1) define nillable="true" in which case you will get xsi:nil="true" in
the instance
2) define minOccurs="0" in which case the element is omitted

You cannot have what you wish unless you define your type as a
derivative of xsd:string where the empty string is a valid value and
then in your code you can covert the empty string to null and vice versa
(but this gives the obvious problem of how to actually pass an empty
string?).

Pete


Robert Lowe wrote:

>What is the schema declared datatype for the pastBalanceDueDate element? I'm
>no schema expert, but if it's declared as "date" or similar, then I think
>your desired output is not valid against the schema.
>
>It would help if you would post at least the relevant part of the schema.
>
>- Rob
>
>
>-----Original Message-----
>From: Brian.Scott_at_mainline.com [mailto:Brian.Scott_at_mainline.com]
>Sent: Friday, August 29, 2003 2:37 AM
>To: users_at_jaxb.dev.java.net
>Subject: Strange output for nillable elements at marshall time
>
>
>Hello friends. I'm wondering if anyone can help me come up with a solution
>to marshall a JAXB object that has null values for some fields that has
>cleaner output than what I see currently. For example, if I do not have
>past balance due date assigned, I might expect the output from the
>marshalling operation to look like this:
>
><otherContent>
><pastBalaneDueDate/>
></otherContent>
>
>Instead, I get the following:
>
><otherContent>
><pastBalanceDueDate ns1:nil="true"
>xmlns:ns1="http://www.w3.org/2001/XMLSchema-instance"/>
></otherContent>
>
>If I use minOccurs="0" in my .xsd instead of nillable=true, it will simply
>omit the <pastBalanceDueDate/> tag altogether. This is a bit cleaner, I
>suppose, but doesn't really get me to the solution I think should be
>available with a little more work. I can post the full .xsd if anyone
>thinks it will help.
>
>Thanks!
>
>brian
>This e-mail and files transmitted with it are confidential, and are
>intended solely for the use of the individual or entity to whom this e-mail
>is addressed. If you are not the intended recipient, or the employee or
>agent responsible to deliver it to the intended recipient, you are hereby
>notified that any dissemination, distribution or copying of this
>communication is strictly prohibited. If you are not one of the named
>recipient(s) or otherwise have reason to believe that you received this
>message in error, please immediately notify sender by e-mail, and destroy
>the original message. Thank You.
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
>For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
>For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net