I feel your pain - we quite often have tags with entries for three formats (JSON, YAML and BSON) - but I'm not sure that collapsing them is necessarily a good idea, as the named tags indicate that the object is explicitly intended to be able to be marshaled with those formats.
That said, it's quite common for us to have an issue where someone has (say) tagged for YAML but not for JSON. Given that there is (more-or-less) a standard subset of the tags that works between encodings, maybe it would make sense to have a standard tag that could be used for all of them, similarly to the way that TextUnmarshaler and TextMarshaler are supported across most encodings. For example: type Payment struct { ActionType paypal.ActionType `encode:"actionType,omitempty"` ReceiverList paypal.ReceiverList `encode:"actionType,omitempty"` } One would need to define the format quite carefully, and perhaps define things so that attributes not recognised by a particular encoder are ignored (allowing, for example, an XML-specific "attr" tag without preventing JSON from using it) Then of course every existing encoder would need to be updated to recognise it... cheers, rog. On 19 June 2016 at 13:42, 'Mihai B' via golang-nuts <golang-nuts@googlegroups.com> wrote: > Hi there, > > I have a struct that needs to be marshalled/unmarshalled using various > serialization formats(xml, json, name/value). The tags start to represent a > considerable effort[0] so I'm wondering if this is a common use case and if > a change[1] to the encoding packages to specify the tag key/selectors would > be a bad idea. Another option would be to use a standard tag key as default > (e.g. "encoding") but I think it may violate the Go1 backward > compatibility. > > Mihai. > > > [0] > type Payment struct { > ActionType paypal.ActionType `query:"actionType,omitempty" > json:"actionType,omitempty" xml:"actionType,omitempty"` > ReceiverList paypal.ReceiverList `query:"actionType,omitempty" > json:"receiverList,omitempty" xml:"receiverList,omitempty"` > } > > > [1] (dec *Decoder)SetTagKey(key string) > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.