Skip to content
Permalink
Browse files

Properly Format BigDecimal Attributes.

This builds on eed3si9n#483.
The case is not solved when `toXML` is called for a generated class and one of its attribute is a BigDecimal.
  • Loading branch information...
tOverney committed Apr 5, 2019
1 parent dddfbfb commit cc7a593c84e1ee010b9e57ada4358c1e386ed1f8
@@ -115,6 +115,7 @@ trait XMLOutput extends Args {
case symbol: BuiltInSimpleTypeSymbol =>
buildTypeName(symbol) match {
case "javax.xml.namespace.QName" => "scalaxb.Helper.toString(%s, __scope)" format selector
case "BigDecimal" => selector + ".bigDecimal.toPlainString"
case _ => selector + ".toString"
}
case ReferenceTypeSymbol(decl: SimpleTypeDecl) =>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:element name="foo">
<xs:complexType>
<xs:sequence>
<xs:element name="attribute1" type="xs:decimal"/>
<xs:element name="optionalAttribute" type="xs:decimal" use="optional"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
@@ -0,0 +1,28 @@
import java.io.{File}

object WithBigDecimalTest extends TestBase {
val inFile = new File("integration/src/test/resources/withbigdecimal.xsd")
lazy val generated = module.process(inFile, "bigdecimal", tmp)

"withbigdecimal.scala must properly format BigDecimal attributes" in {
(List("import scalaxb._",
"import bigdecimal._",
"""val document = <foo xmlns:xs="http://www.w3.org/2001/XMLSchema"
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
| <attribute1>2300</attribute1>
| <optionalAttribute>0.00002</optionalAttribute>
|</foo>""".stripMargin,
"""toXML[Foo](fromXML[Foo](document),
None, Some("foo"), scalaxb.toScope(
Some("xs") -> "http://www.w3.org/2001/XMLSchema",
Some("xsi") -> "http://www.w3.org/2001/XMLSchema-instance"
)).toString"""
),
generated) must evaluateTo(
"""<foo xmlns:xs="http://www.w3.org/2001/XMLSchema" """ +
"""xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">""" +
"""<attribute1>2300</attribute1>""" +
"""<optionalAttribute>0.00002</optionalAttribute></foo>""",
outdir = "./tmp")
}
}

0 comments on commit cc7a593

Please sign in to comment.
You can’t perform that action at this time.