Keith, I wish I could help, but unfortunately I cannot.
Until nillable is implemented may I request an option that allows the user to convert null fields into empty tags then? Or perhaps someone can point me to where this decision point is made in the code? Dan -----Original Message----- From: Keith Visco [mailto:kvisco@;intalio.com] Sent: Wednesday, November 06, 2002 5:08 PM To: [EMAIL PROTECTED] Subject: Re: [castor-dev] Problem: Castor's handling of nulls when generating XML Hi Daniel, I suppose it depends on your definition of NULL and your definition of empty, which are quite different things. For example, using your definition below: MyTextField = ""; will produce a valid, but empty tag in the XML. However, MyTextField = null; will not produce anything, which to me is what I expect. The two cases should definately should be treated differently. If both were handled the same way, castor wouldn't know how to unmarshal the field. Should it create an empty string or a null string. One way to solve this is to support the xsi:nil attribute, signalling that the empty element means it is null and not simply empty. However we do not yet support the nillable / xsi:nil attributes at this time. I don't believe anyone is currently working on it, so if it's something that interests you, then maybe you want to take a shot at implementing it. --Keith Daniel Kirkdorffer wrote: > > Keith, > > I think the issue is a matter of what Castor's definition of a required > field is. > > minOccurs=1 is all about the XML tag: there must be one. It is not a > definition of the content of the tag, which could be empty. > > For example, we have a tag defined as such: > > <xs:element name="MyTextField" minOccurs="1"> > <xs:simpleType> > <xs:restriction base="xs:string"> > <xs:maxLength value="20"/> > </xs:restriction> > </xs:simpleType> > </xs:element> > > Castor generates a validation rule like so: > > desc.setRequired(true); > > Conversly in XMLFieldDescriptorImpl, Castor has: > > if (_required) { > _validator = new FieldValidator(); > _validator.setMinOccurs(1); > _validator.setDescriptor(this); > } > > The problem is a value of NULL that might come out of a database or > something, has no bearing on the required status of the tag in the XSD. All > the XSD is saying is that the tag should exist. But it could be blank. > Castor, in my mind, erroneously disregards NULL values when it fails to > produce an empty tag. > > This is an even bigger problem for numeric or date fields. Null has a > meaning of emptiness that is still valid, yet Castor doesn't generate that > important tag in those cases. > > So this is a summary: > - What Castor is doing: > if field = null, > then Castor produces no corresponding tag > > - What I think it should be doing: > if field = null > then Castor produces an empty tag (</field>) > > - Alternatively, Castor gives us a configurable choice. > > The workarounds to deal with this are hugely invasive otherwise and almost > completely negate the benefits Castor provides. > > Dan > > -----Original Message----- > From: Keith Visco [mailto:kvisco@;intalio.com] > Sent: Wednesday, November 06, 2002 2:52 PM > To: [EMAIL PROTECTED] > Subject: Re: [castor-dev] Problem: Castor's handling of nulls when > generating XML > > Hi Daniel, > > If you're using Castor generated source code, and the tag is required, a > ValidationException should be thrown indicating that a required field is > missing if the field is null. Unless of course you have disabled > validation, in which case there is nothing we can do about that. > > If you're using a mapping file you'll have to explicitely say that the > field is required. > > If you have validation enabled (it is by default), and you are using > source generation or mapping file with required for the proper fields, > then please provide a test case which demonstrates the problem so that > we can help track down the issue. > > Thanks, > > --Keith > > Daniel Kirkdorffer wrote: > > > > We're running into a situation where we are working with Castor 0.9.4 to > > produce XML. The issue is how Castor deals with nulls. Instead of > > producing empty XML element tags, Castor omits the tag entirely. If the > tag > > was optional this isn't a problem, but when it is required, empty or not, > it > > is a big problem. > > > > Has anyone on this list has had to deal with this before and can suggest a > > solution, or knows of a configuration settings that solves the problem. > > > > Thanks, > > > > Dan > > > > -- > > Daniel Kirkdorffer > > Sr. Developer > > Versatile Mobile Systems > > Work: 425-673-5933 > > Cell: 206-399-1367 > > > > ----------------------------------------------------------- > > If you wish to unsubscribe from this mailing, send mail to > > [EMAIL PROTECTED] with a subject of: > > unsubscribe castor-dev > > ----------------------------------------------------------- > If you wish to unsubscribe from this mailing, send mail to > [EMAIL PROTECTED] with a subject of: > unsubscribe castor-dev > > ----------------------------------------------------------- > If you wish to unsubscribe from this mailing, send mail to > [EMAIL PROTECTED] with a subject of: > unsubscribe castor-dev ----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to [EMAIL PROTECTED] with a subject of: unsubscribe castor-dev ----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to [EMAIL PROTECTED] with a subject of: unsubscribe castor-dev
