From 2cb8c451ebb96ba5d22e50137563ea1af144003d Mon Sep 17 00:00:00 2001 From: "i.anferov" Date: Tue, 14 Jul 2020 17:36:35 +0500 Subject: [PATCH] Duplicated json values on marshalind interfaces implementing easyjson.Marshaler --- gen/encoder.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/gen/encoder.go b/gen/encoder.go index 893d9e8..74c530f 100644 --- a/gen/encoder.go +++ b/gen/encoder.go @@ -274,14 +274,15 @@ func (g *Generator) genTypeEncoderNoCheck(t reflect.Type, in string, tags fieldT } else { return fmt.Errorf("interface type %v not supported: only interface{} and interfaces that implement json or easyjson Marshaling are allowed", t) } + } else { + fmt.Fprintln(g.out, ws+"if m, ok := "+in+".(easyjson.Marshaler); ok {") + fmt.Fprintln(g.out, ws+" m.MarshalEasyJSON(out)") + fmt.Fprintln(g.out, ws+"} else if m, ok := "+in+".(json.Marshaler); ok {") + fmt.Fprintln(g.out, ws+" out.Raw(m.MarshalJSON())") + fmt.Fprintln(g.out, ws+"} else {") + fmt.Fprintln(g.out, ws+" out.Raw(json.Marshal("+in+"))") + fmt.Fprintln(g.out, ws+"}") } - fmt.Fprintln(g.out, ws+"if m, ok := "+in+".(easyjson.Marshaler); ok {") - fmt.Fprintln(g.out, ws+" m.MarshalEasyJSON(out)") - fmt.Fprintln(g.out, ws+"} else if m, ok := "+in+".(json.Marshaler); ok {") - fmt.Fprintln(g.out, ws+" out.Raw(m.MarshalJSON())") - fmt.Fprintln(g.out, ws+"} else {") - fmt.Fprintln(g.out, ws+" out.Raw(json.Marshal("+in+"))") - fmt.Fprintln(g.out, ws+"}") default: return fmt.Errorf("don't know how to encode %v", t) }