Duplicated json values on marshalind interfaces implementing easyjson.Marshaler

This commit is contained in:
i.anferov
2020-07-14 17:36:35 +05:00
parent 8ba3c7bdce
commit 2cb8c451eb
+8 -7
View File
@@ -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)
}