-
Notifications
You must be signed in to change notification settings - Fork 181
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
Union serialization defaults to widest data type, which may or may not be ideal #399
Comments
The difference appears to be: [System.ComponentModel.DataAnnotations.RequiredAttribute()]
[System.Xml.Serialization.XmlAttributeAttribute("Date")]
public DateTime DateObject { get; set; } vs. [System.ComponentModel.DataAnnotations.RequiredAttribute()]
[System.Xml.Serialization.XmlAttributeAttribute("Date", DataType="date")]
public System.DateTime Date { get; set; } Obviously, widening is the only approach where data type unification makes sense. So, it's really just a matter of whether or not that is the right value to send, semantically. - That's not something an XSD Validator can tell us, for example, as it's API behavior-defined by the vendor. Incidentally, Microsoft defines the list of XSD data types they support, here: https://learn.microsoft.com/en-us/dotnet/api/system.xml.serialization.xmlattributeattribute.datatype?view=net-7.0#remarks (I did not know this, and was just reading the source to figure it out). |
Possible alternatives, which may be pretty complex:
For Tagged Unions, the approach would be:
|
Some possible inspiration here: https://github.com/dpraimeyuu/OneOf.Serialization - it does Json, not Xml. Practically speaking, the only way to implement Xml support on a complex type like OneOfBase-derived instances would probably be to implement IXmlSerializable. Unless I am missing something? It's been a decade since I was deep into XML APIs in .NET. |
Originally posted by @jzabroski in #397 (comment)
The text was updated successfully, but these errors were encountered: