xs:choice generates DataRecord[Any]
alexandru opened this issue · comments
Hello,
I have the following type described in the xsd:
<xs:complexType name="AccountIdentification4Choice">
<xs:choice>
<xs:element name="IBAN" type="IBAN2007Identifier"/>
<xs:element name="Othr" type="GenericAccountIdentification1"/>
</xs:choice>
</xs:complexType>
This is clearly a union type. But the type generated is:
case class AccountIdentification4Choice(
accountidentification4choiceoption: scalaxb.DataRecord[Any]
)
I would have expected to see something like:
sealed trait AccountIdentification4Choice
object AccountIdentification4Choice {
case class IBAN(value: IBAN2007Identifier) extends AccountIdentification4Choice
case class Othr(value: GenericAccountIdentification1) extends AccountIdentification4Choice
}
Any way to prevent the use of that DataRecord[Any]
?
I'll copy this here for the record:
https://twitter.com/eed3si9n/status/1339183897498804225
apparently I blogged about it ten years ago
https://scalaxb.org/narrower-choice
https://twitter.com/alexelcu/status/1339187282637631490
Thanks, haven't seen that.
I wonder why you found it necessary to look for a super-type (e.g. Addressable) instead of wrapping that thing in a union type. The natural representation for the choice in that article would be something like:
https://gist.github.com/alexandru/c74f15070dba2dcb4a23977633bd8815
I think it's good to reexamine earlier design decisions. If I first try to remember my thinking back then, the theme that I kept coming back to is what types represent with regard to data binding some XML document like:
<address>
<name>John</name>
</address>
If we used case class:
case class Address(name: String)
then, the type String
represent an xsd:type
, the field name: String
represent an xsd:element
. Or to put another way, String
represents what is in between the angle brackets <name>
... </name>
.
If so, what does the case class Address
represent? It also represent what is in between <address>
... </address>
, and thus case class alone is not enough information to represent the whole of the XML document. It needs to be a field:
address: Address
this field is what DataRecord[A]
represents. I almost want a union of literal-and-a-type pairs like:
("groundShipping".type, Address)
| ("twoDayShipping".type, Address)
| ("oneDayShipping".type, Address)
| ("internalShipping".type, InternalAddress)