remove stringer in MarshalJSON

This commit is contained in:
Yannick Briffa 2018-03-07 15:16:34 +01:00
parent c64b41d7d9
commit 41fbf3154e

View File

@ -64,10 +64,11 @@ func init() {
// MarshalJSON is generated so {{$typename}} satisfies json.Marshaler. // MarshalJSON is generated so {{$typename}} satisfies json.Marshaler.
func (r {{$typename}}) MarshalJSON() ([]byte, error) { func (r {{$typename}}) MarshalJSON() ([]byte, error) {
{{ if not $noStringer -}}
if s, ok := interface{}(r).(fmt.Stringer); ok { if s, ok := interface{}(r).(fmt.Stringer); ok {
return json.Marshal(s.String()) return json.Marshal(s.String())
} }
s, ok := _{{$typename}}ValueToName[r] {{ end }}s, ok := _{{$typename}}ValueToName[r]
if !ok { if !ok {
return nil, fmt.Errorf("invalid {{$typename}}: %d", r) return nil, fmt.Errorf("invalid {{$typename}}: %d", r)
} }