liip/sheriff

XML Marshalling Support

weisjohn opened this issue · 3 comments

Hey there, great library. I'm hoping to use it, however, when trying to use xml.Marshal, I get no output. Is there a way to add in support for this? I'm happy to do it if you give me a pointer or two.

Hey @weisjohn,
thanks for the interest.
At the moment there's only json marshalling implemented. To add XML marshalling there are a couple of things which would need to be done.

  1. Your structs would need to be annotated with the xml field tags (see an example here https://golang.org/pkg/encoding/xml/#MarshalIndent)
  2. Most likely the XML tags would need to be read alongside the JSON tags (https://github.com/liip/sheriff/blob/master/sheriff.go#L75)
  3. Another exception might need to be added for XML marshalling here: https://github.com/liip/sheriff/blob/master/sheriff.go#L165

I'm not entirely sure if that's all there is to be done because of the different structure of XML (attributes etc.). sheriff.Marshal returns a map[string]interface{} when passed a struct, which then can be passed to json.Marshal. As XML marshalling is quite a bit different, I'm unsure if that would work for XML marshalling too.
It's worth a try and if you try it out I can help you on the way most likely. Currently don't have the time to do that on my own though.

Let me know if you have further questions!

Any update @weisjohn?

@mweibel nope, sorry, no update. I've moved on from needing this, unfortunately.