I'm trying to format a custom time type, Date, that implements the Marshaler interface and simply formats itself as "2006-01-02" when written as XML.
type Person struct {
...
DateOfBirth Date `xml:"DOB,attr"`
...
}
type Date time.Time
func (d Date) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
dateString := fmt.Sprintf("\"%v\"", time.Time(d).Format("2006-01-02"))
e.EncodeElement(dateString, start)
return nil
}
I was using this SO as a reference, but the error - &xml.UnsupportedTypeError{Type:(*reflect.rtype)} - is thrown.
I'm missing something, any ideas?