Board index » delphi » Serializing Integer values when nillable="true"

Serializing Integer values when nillable="true"


2006-12-19 10:51:32 AM
delphi237
Hi guys,
In the WSDL definition for a web service I have been supplied, it defines
some integer elements as nillable="true"
Here's an example...
<complexType name="NumberNetworkUpdateData">
<sequence>
<element name="donorCarrierId" nillable="true" type="soapenc:int"/>
<element name="gainingCarrierId" nillable="true" type="soapenc:int"/>
<element name="losingCarrierId" nillable="true" type="soapenc:int"/>
<element name="number" nillable="true" type="tns1:PhoneNumberData"/>
</sequence>
</complexType>
This is fine until Serialization occurs where a conversion exception is
raised "'' is not a valid integer"
The SOAP I receive looks like this...
<numbers>
<donorCarrierId>99897</donorCarrierId>
<gainingCarrierId xsi:nil="true"/>
<losingCarrierId>11647</losingCarrierId>
<number>
<phoneNumber>0299959902</phoneNumber>
</number>
</numbers>
As you can see, for this instance the gainingCarrierID is nil which causes
problems.
Is there some way to get around this problem without modifying Delphi
supplied Source?
Thanks for any help :)
Mark England
 
 

Re:Serializing Integer values when nillable="true"

Hello Mark,
The nillable issue is somehow problematic for Delphi because integers (and
other built-in types, such as String or WideString - as you can imagine,
this problem happens a lot for xsd:string types) cannot be nil.
That said, the serialization logic should not attempt to convert and empty
string to an integer. It should check for the 'nil' attribute. I am making a
note to investigate this and make sure it is addressed.
To answer your question, in general users have worked around the nillable
issue by using a TXS-derived type. We do that already for xsd:dateTime and a
few other XML types. The drawback is that working with a TXSDateTime is not
as easy as with a DateTime - you have to manage via TXSDateTime.Create and
TXSDateTime.Free calls. (We do when we're the one converting from XML to
native). But again, Delphi's DateTime cannot represent the richness of XML
xsd:dateTime... The serialization logic works either way but there's
potential for data being lost in the case of plain DateTime...
There is no TXSString but it is easy to define your own and then use that
instead of plain WideString/string in the place where a nillable string is
possible. Let me know if you need more information. I am also making a note
to allow an option whereby the importer could be instructed to switch to a
TXSxxxx type for nillable elements.
Cheers,
Bruneau.
 

Re:Serializing Integer values when nillable="true"

Thanks for the reply,
I'm finding that the TXSDateTime object is raising an exception when a nil
value is passed to it also... I have created my own types to get around this
to a degree however I thought I'd mention it.
Thanks,
Mark England
 

Re:Serializing Integer values when nillable="true"

Hello Mark,
I am aware of this issue and have addressed it in the upcoming hotfix. I'll
double check this but remember running into this issue (that and the fact
that TXSxxxx classes did not lend themselves to being attributes). Thanks
for the report.
Cheers,
Bruneau.