Re: [go-nuts] Unmarshalling and tags
I'd like to see something like this: type Payment struct { ActionType paypal.ActionType `xml,yaml,json:"actionType,omitempty"` ReceiverList paypal.ReceiverList `xml,yaml,json:"actionType,omitempty"` } -- 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.
Re: [go-nuts] Unmarshalling and tags
teisipäev, 21. juuni 2016 9:47.54 UTC+3 kirjutas rog: > > 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. > Another idea is to allow the tags to be defined by more than one string: type Payment struct { ActionType paypal.ActionType `xml:"actionType,omitempty"` `json:"action"` ReceiverList paypal.ReceiverList `xml:"receiverList,omitempty"` `json:"receiver"` } compiler would concatenate them into single string so all code will continue to work but this would allow the gofmt to align them into neat columns, making it easier to read. ain -- 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.
Re: [go-nuts] Unmarshalling and tags
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-nutswrote: > 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.
Re: [go-nuts] Unmarshalling and tags
2016-06-19 12:42 GMT+02:00 'Mihai B' via golang-nuts: > 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"` > } For what it's worth, in cases where I've needed to do this the tags have often differed for the various formats. type SomeOptions struct { ... AlwaysLocalNets []string `xml:"alwaysLocalNet" json:"alwaysLocalNets"` DeprecatedUPnPEnabled bool `xml:"upnpEnabled,omitempty" json:"-"` ... } For slices, the plural case differs as you want "items": ["foo", "bar"] in JSON but foobar in XML. The deprecated option should be read from the XML source but omitted in the JSON response. And so on. //jb -- 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.
[go-nuts] Unmarshalling and tags
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.