Skip to content
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

xs:choice generates DataRecord[Any] #549

Open
alexandru opened this issue Dec 16, 2020 · 2 comments
Open

xs:choice generates DataRecord[Any] #549

alexandru opened this issue Dec 16, 2020 · 2 comments

Comments

@alexandru
Copy link

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]?

@eed3si9n
Copy link
Owner

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

@eed3si9n
Copy link
Owner

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants