scalasoapscalaxb

Compilation error in scalaxb generated code (xmlprotocol.scala) - found: Boolean, required: Option[Boolean]


I'm getting a compilation error in xmlprotocol.scala generated by latest scalaxb (1.1.2) from a large WSDL file:

[info] Compiling 10 Scala sources to /aw-scalaxb-test/target/scala-2.10/classes...
[error] /aw-scalaxb-test/target/scala-2.10/src_managed/main/sbt-scalaxb/aw/xmlprotocol.scala:630: type mismatch;
[error]  found   : Boolean
[error]  required: Option[Boolean]
[error]         p2.headOption map { scalaxb.fromXML[Boolean](_, scalaxb.ElemName(node) :: stack) } getOrElse { scalaxb.fromXML[Boolean](scala.xml.Text("false"), scalaxb.ElemName(node) :: stack) },
[error]                                                                                                                                    ^
[error] one error found
[error] (compile:compile) Compilation failed

Here is a corresponding piece of code (the error is on first "p2.headOption map" line):

...
(scalaxb.ElemName(None, "HistoryLastDate"))) ^^ 
    { case p1 ~ p2 ~ p3 ~ p4 ~ p5 ~ p6 ~ p7 ~ p8 ~ p9 ~ p10 => aw.CheckAccountRequestSequence2(p1.nilOption map { scalaxb.fromXML[Int](_, scalaxb.ElemName(node) :: stack) },
    p2.headOption map { scalaxb.fromXML[Boolean](_, scalaxb.ElemName(node) :: stack) } getOrElse { scalaxb.fromXML[Boolean](scala.xml.Text("false"), scalaxb.ElemName(node) :: stack) },
    p3.nilOption map { scalaxb.fromXML[String](_, scalaxb.ElemName(node) :: stack) },
...

The error seems strange to me since there are several very similar constructions in the code around. Are all of them generated wrong?

Can anyone give me a hint what is wrong here?

Original WSDL and all code is in my github project: https://github.com/alboko/aw-scalaxb-test


Solution

  • After some investigation, I believe it is a bug in handling "default=" attributes in elements like:

    <xsd:element name="ParseItineraries" type="xsd:boolean" nillable="true" default="false">
    

    scalaxb generates something like

    p2.headOption map { 
          scalaxb.fromXML[Boolean](_, scalaxb.ElemName(node) :: stack) 
    } getOrElse { 
          scalaxb.fromXML[Boolean](scala.xml.Text("false"), scalaxb.ElemName(node) :: stack) 
    }
    

    which causes the compilation error. If I remove the default attribute, it generates

    p2.nilOption map { scalaxb.fromXML[Boolean](_, scalaxb.ElemName(node) :: stack) }
    

    which compiles without any issues.

    Created issue #245 for scalaxb in GitHub. @eed3si9n suspects that it is a bug in scalaxb.