diff --git a/accounting/grpc/service_frostfs.pb.go b/accounting/grpc/service_frostfs.pb.go index b70fd27..4f11303 100644 Binary files a/accounting/grpc/service_frostfs.pb.go and b/accounting/grpc/service_frostfs.pb.go differ diff --git a/accounting/grpc/types_frostfs.pb.go b/accounting/grpc/types_frostfs.pb.go index 182705e..0ae770b 100644 Binary files a/accounting/grpc/types_frostfs.pb.go and b/accounting/grpc/types_frostfs.pb.go differ diff --git a/acl/grpc/types_frostfs.pb.go b/acl/grpc/types_frostfs.pb.go index b055167..57e1682 100644 Binary files a/acl/grpc/types_frostfs.pb.go and b/acl/grpc/types_frostfs.pb.go differ diff --git a/ape/grpc/types_frostfs.pb.go b/ape/grpc/types_frostfs.pb.go index e19d9f6..7967e13 100644 Binary files a/ape/grpc/types_frostfs.pb.go and b/ape/grpc/types_frostfs.pb.go differ diff --git a/apemanager/grpc/service_frostfs.pb.go b/apemanager/grpc/service_frostfs.pb.go index 99abeb2..2a30850 100644 Binary files a/apemanager/grpc/service_frostfs.pb.go and b/apemanager/grpc/service_frostfs.pb.go differ diff --git a/container/grpc/service_frostfs.pb.go b/container/grpc/service_frostfs.pb.go index ffdc730..4ccb595 100644 Binary files a/container/grpc/service_frostfs.pb.go and b/container/grpc/service_frostfs.pb.go differ diff --git a/container/grpc/types_frostfs.pb.go b/container/grpc/types_frostfs.pb.go index 3010eb0..9db07ed 100644 Binary files a/container/grpc/types_frostfs.pb.go and b/container/grpc/types_frostfs.pb.go differ diff --git a/lock/grpc/types_frostfs.pb.go b/lock/grpc/types_frostfs.pb.go index 58be895..33f22c5 100644 Binary files a/lock/grpc/types_frostfs.pb.go and b/lock/grpc/types_frostfs.pb.go differ diff --git a/netmap/grpc/service_frostfs.pb.go b/netmap/grpc/service_frostfs.pb.go index 3d62855..4d53031 100644 Binary files a/netmap/grpc/service_frostfs.pb.go and b/netmap/grpc/service_frostfs.pb.go differ diff --git a/netmap/grpc/types_frostfs.pb.go b/netmap/grpc/types_frostfs.pb.go index 43af103..d082910 100644 Binary files a/netmap/grpc/types_frostfs.pb.go and b/netmap/grpc/types_frostfs.pb.go differ diff --git a/object/grpc/service_frostfs.pb.go b/object/grpc/service_frostfs.pb.go index 188d032..2434bd3 100644 Binary files a/object/grpc/service_frostfs.pb.go and b/object/grpc/service_frostfs.pb.go differ diff --git a/object/grpc/types_frostfs.pb.go b/object/grpc/types_frostfs.pb.go index 9fc2769..5b1eb2c 100644 Binary files a/object/grpc/types_frostfs.pb.go and b/object/grpc/types_frostfs.pb.go differ diff --git a/refs/grpc/types_frostfs.pb.go b/refs/grpc/types_frostfs.pb.go index 5f35eba..869620f 100644 Binary files a/refs/grpc/types_frostfs.pb.go and b/refs/grpc/types_frostfs.pb.go differ diff --git a/session/grpc/service_frostfs.pb.go b/session/grpc/service_frostfs.pb.go index aa42ee8..a3f0111 100644 Binary files a/session/grpc/service_frostfs.pb.go and b/session/grpc/service_frostfs.pb.go differ diff --git a/session/grpc/types_frostfs.pb.go b/session/grpc/types_frostfs.pb.go index c92ab28..58807fe 100644 Binary files a/session/grpc/types_frostfs.pb.go and b/session/grpc/types_frostfs.pb.go differ diff --git a/status/grpc/types_frostfs.pb.go b/status/grpc/types_frostfs.pb.go index 29dfebe..7581dbe 100644 Binary files a/status/grpc/types_frostfs.pb.go and b/status/grpc/types_frostfs.pb.go differ diff --git a/tombstone/grpc/types_frostfs.pb.go b/tombstone/grpc/types_frostfs.pb.go index f7bc48c..79afdfc 100644 Binary files a/tombstone/grpc/types_frostfs.pb.go and b/tombstone/grpc/types_frostfs.pb.go differ diff --git a/util/proto/test/custom/test_frostfs.pb.go b/util/proto/test/custom/test_frostfs.pb.go index 005d6d1..03f3ece 100644 Binary files a/util/proto/test/custom/test_frostfs.pb.go and b/util/proto/test/custom/test_frostfs.pb.go differ diff --git a/util/protogen/internalgengo/json.go b/util/protogen/internalgengo/json.go index 95a06d5..ec70155 100644 --- a/util/protogen/internalgengo/json.go +++ b/util/protogen/internalgengo/json.go @@ -147,8 +147,11 @@ func emitJSONMarshal(g *protogen.GeneratedFile, msg *protogen.Message) { g.P("func (x *", msg.GoIdent.GoName, ") MarshalEasyJSON(out *", jwriterPackage.Ident("Writer"), ") {") g.P(`if x == nil { out.RawString("null"); return }`) + if len(msg.Fields) != 0 { + g.P("first := true") + } g.P("out.RawByte('{')") - for i, f := range msg.Fields { + for _, f := range msg.Fields { if f.Oneof != nil { if f.Oneof.Fields[0] != f { continue @@ -157,29 +160,35 @@ func emitJSONMarshal(g *protogen.GeneratedFile, msg *protogen.Message) { g.P("switch xx := x.", f.Oneof.GoName, ".(type) {") for _, ff := range f.Oneof.Fields { g.P("case *", ff.GoIdent, ":") - emitJSONFieldWrite(g, ff, "xx", i == 0) + emitJSONFieldWrite(g, ff, "xx") } g.P("}") continue } - emitJSONFieldWrite(g, f, "x", i == 0) + emitJSONFieldWrite(g, f, "x") } g.P("out.RawByte('}')") g.P("}") } -func emitJSONFieldWrite(g *protogen.GeneratedFile, f *protogen.Field, name string, first bool) { +func emitJSONFieldWrite(g *protogen.GeneratedFile, f *protogen.Field, name string) { g.P("{") defer g.P("}") - g.P("const prefix string = ", `",\"`, fieldJSONName(f), `\":"`) - if first { - g.P("out.RawString(prefix[1:])") - } else { - g.P("out.RawString(prefix)") - } - selector := name + "." + f.GoName + + isNotDefault := notNil + if f.Desc.IsList() { + isNotDefault = notEmpty + } else if f.Desc.Kind() != protoreflect.MessageKind { + _, isNotDefault = easyprotoKindInfo(f.Desc.Kind()) + } + g.P("if ", isNotDefault(selector), "{") + defer g.P("}") + + g.P("if !first { out.RawByte(','); } else { first = false; }") + g.P("const prefix string = ", `"\"`, fieldJSONName(f), `\":"`) + g.P("out.RawString(prefix)") if f.Desc.IsList() { selector += "[i]" g.P("out.RawByte('[')")