diff --git a/accounting/grpc/service_frostfs.pb.go b/accounting/grpc/service_frostfs.pb.go index b70fd275..4f113030 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 182705e6..0ae770b3 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 b0551673..57e16821 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 e19d9f69..7967e131 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 99abeb29..2a30850a 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 ffdc7306..4ccb595e 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 3010eb06..9db07ed3 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 58be8957..33f22c58 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 3d628558..4d530313 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 43af1037..d082910e 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 188d0326..2434bd3b 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 9fc27697..5b1eb2c3 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 5f35eba2..869620f8 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 aa42ee8f..a3f01112 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 c92ab28b..58807fef 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 29dfebe5..7581dbe9 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 f7bc48c4..79afdfcd 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 005d6d11..03f3ece6 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 95a06d59..ec70155b 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('[')")