-
Notifications
You must be signed in to change notification settings - Fork 18k
encoding/xml: serialization of interface{}
attribute is unsupported, even when dynamic type implements relevant interfaces
#48624
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
Comments
Change https://golang.org/cl/352229 mentions this issue: |
If your type actually implements the XML marshaller interface, why not just make the field of type
? It might be a usability improvement to just have the code check if the empty interface implements one of these, but should it check this for any interface type? What's special about empty interface here? CC @rsc via https://dev.golang.org/owners |
interface{}
attribute is unsupported, even when dynamic type implements relevant interfaces
Well, my type does, but types like
What's special about the empty interface is that the behaviour is different depending on if it is a value (which works) or an attribute, and then also if the attribute is a basic type (also works) or not. This seems to be caused by the fact that the marshalling of XML values and attributes happens somewhat differently: Also note that the given error is incorrect, which seems like a proper bug to me. This is caused by the error being created after de-referencing the interface. |
Oof. That does seem like an inconsistency, given that it checks for both basic types or if it's a value. Thanks for the additional info. |
Change https://go.dev/cl/606495 mentions this issue: |
What version of Go are you using (
go version
)?Also reproduces on the playground (see below).
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
When marshalling a struct with an interface field to an XML attribute, an error is returned. Simple example, extended example.
What did you expect to see?
No error, and for the simple example:
The extended example should return:
What did you see instead?
This error is incorrect (
time.Time
implementsencoding.TextMarshaler
), so should be supported.Additionally, this does work with values instead of attributes, as shown in the extended example:
The text was updated successfully, but these errors were encountered: