package versioning import "encoding/json" func (v *Version) UnmarshalJSON(data []byte) error { // try parse from string if data[0] == '"' { tmp, err := ParseVersion(string(data[1 : len(data)-1])) if err != nil { return err } *v = tmp return nil } var code uint32 if err := json.Unmarshal(data, &code); err != nil { return err } tmp, err := ParseVersionFromCode(code) if err != nil { return err } *v = tmp return nil } func (v Version) MarshalJSON() ([]byte, error) { return json.Marshal(v.String()) }