New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parser throws unhelpful NumberFormatException on empty xml elements violating schema #206

Closed
caoilte opened this Issue Apr 6, 2013 · 3 comments

Comments

Projects
None yet
3 participants
@caoilte

caoilte commented Apr 6, 2013

I was getting an empty element returned by our SOAP server for an optional field. According to

http://scalaxb.org/nillable

this shouldn't happen (most other SOAP clients seem to swallow the problem)

I'm fine with Scalaxb exploding, however it took me a while to diagnose why from the following stack

[info]   scalaxb.ParserFailure: java.lang.NumberFormatException: Zero length BigInteger
[info]   at scalaxb.package$.fromXML(scalaxb.scala:15)
[info]   at venus.paris.generated.XMLProtocol$DefaultSyndicationrequestProductionFormat$$anonfun$parser$30$$anonfun$apply$29$$anonfun$apply$30.apply(xmlprotocol.scala:818)
[info]   at venus.paris.generated.XMLProtocol$DefaultSyndicationrequestProductionFormat$$anonfun$parser$30$$anonfun$apply$29$$anonfun$apply$30.apply(xmlprotocol.scala:818)
[info]   at scala.Option.map(Option.scala:145)
[info]   at venus.paris.generated.XMLProtocol$DefaultSyndicationrequestProductionFormat$$anonfun$parser$30$$anonfun$apply$29.apply(xmlprotocol.scala:818)
[info]   at venus.paris.generated.XMLProtocol$DefaultSyndicationrequestProductionFormat$$anonfun$parser$30$$anonfun$apply$29.apply(xmlprotocol.scala:818)
[info]   at scala.Option.map(Option.scala:145)
[info]   at venus.paris.generated.XMLProtocol$DefaultSyndicationrequestProductionFormat$$anonfun$parser$30.apply(xmlprotocol.scala:818)
[info]   at venus.paris.generated.XMLProtocol$DefaultSyndicationrequestProductionFormat$$anonfun$parser$30.apply(xmlprotocol.scala:815)
[info]   at scala.util.parsing.combinator.Parsers$Success.map(Parsers.scala:136)

An error which indicates which field had the problem would have saved me from trawling through hundreds of fields in my data and removing them by trial and error.

@eed3si9n

This comment has been minimized.

Show comment
Hide comment
@eed3si9n

eed3si9n Apr 9, 2013

Owner

I was getting an empty element returned by our SOAP server for an optional field.

Is it declared optional (minOccurs=0 maxOccurs=1) or nillable (nillable="true") in the schema? If either is the case, could you share the portion of the schema? It shouldn't explode if some element is supposed to be optional, and is missing from the document.

An error which indicates which field had the problem would have saved me from trawling through hundreds of fields in my data and removing them by trial and error.

I probably could provide some context to the exception message to help debug.

Owner

eed3si9n commented Apr 9, 2013

I was getting an empty element returned by our SOAP server for an optional field.

Is it declared optional (minOccurs=0 maxOccurs=1) or nillable (nillable="true") in the schema? If either is the case, could you share the portion of the schema? It shouldn't explode if some element is supposed to be optional, and is missing from the document.

An error which indicates which field had the problem would have saved me from trawling through hundreds of fields in my data and removing them by trial and error.

I probably could provide some context to the exception message to help debug.

@caoilte

This comment has been minimized.

Show comment
Hide comment
@caoilte

caoilte Apr 12, 2013

Apologies for the late response. The relevant line in the xsd for the problematic part of the response was

<element name="SalesItemId" type="integer" minOccurs="0" />

which I guess means that it was optional. The problem was that it was returned - it was just empty, ie

<SalesItemId/>

caoilte commented Apr 12, 2013

Apologies for the late response. The relevant line in the xsd for the problematic part of the response was

<element name="SalesItemId" type="integer" minOccurs="0" />

which I guess means that it was optional. The problem was that it was returned - it was just empty, ie

<SalesItemId/>

@eed3si9n eed3si9n closed this in 3823d03 Apr 13, 2013

@jeroenvlek

This comment has been minimized.

Show comment
Hide comment
@jeroenvlek

jeroenvlek Aug 11, 2015

I'm facing the same issue, but for booleans. The problem seems to be that, although the elements are defined as nillable, None is only used if the element isn't there at all. If the element is present, but empty, a parse error ensues.

How should one deal with this? Unfortunately, I have no control over the XMLs I need to parse. For now I will define them as Option[String] and deal with it further along the line.

I'm facing the same issue, but for booleans. The problem seems to be that, although the elements are defined as nillable, None is only used if the element isn't there at all. If the element is present, but empty, a parse error ensues.

How should one deal with this? Unfortunately, I have no control over the XMLs I need to parse. For now I will define them as Option[String] and deal with it further along the line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment