From an OpenApi spec, I’ve generated 150 types with the help of quicktype.
I can use them easily while I’m serializing them in json, but a new customer wish is that serialization can be done in xml too.
But it fails with the message:
Failed to marshal XML: xml: unsupported type: map[string]string
because among the types I’ve generated, such declarations can be encountered.
This problem with xml is known and has a workaround explained in this playground and in few S.O. questions.
Playground suggests defining these methods, for custom serialization:
func (m Map) MarshalXML(e *xml.Encoder, start xml.StartElement) error {...}
func (m *Map) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {...}
But doing that would involve that I find a way to ask quicktype to substitute at generation time each map[string]string
it would place by a main.Map
. And I doubt it’s possible.
I would like to know first if there’s a way to declare some Marshall
, Unmarshall
methods for a “native Go declaration” like map[string]string
without defining a new Type to associate them?
Then, encoder/xml
would use these global methods for map[string]string
at generation time wherever they are encountered.