diff --git a/runtime/marshal_json_test.go b/runtime/marshal_json_test.go index 490e66bab83..5037aea9348 100644 --- a/runtime/marshal_json_test.go +++ b/runtime/marshal_json_test.go @@ -197,6 +197,8 @@ var ( {data: "", json: `""`}, {data: proto.String(""), json: `""`}, {data: "foo", json: `"foo"`}, + {data: []byte("foo"), json: `"Zm9v"`}, + {data: []byte{}, json: `""`}, {data: proto.String("foo"), json: `"foo"`}, {data: int32(-1), json: "-1"}, {data: proto.Int32(-1), json: "-1"}, diff --git a/runtime/marshal_jsonpb.go b/runtime/marshal_jsonpb.go index 7387c8e3976..524ea057ccb 100644 --- a/runtime/marshal_jsonpb.go +++ b/runtime/marshal_jsonpb.go @@ -280,6 +280,17 @@ func decodeNonProtoField(d *json.Decoder, unmarshaler protojson.UnmarshalOptions return nil } if rv.Kind() == reflect.Slice { + if rv.Type().Elem().Kind() == reflect.Uint8 { + var sl []byte + if err := d.Decode(&sl); err != nil { + return err + } + if sl != nil { + rv.SetBytes(sl) + } + return nil + } + var sl []json.RawMessage if err := d.Decode(&sl); err != nil { return err diff --git a/runtime/marshal_jsonpb_test.go b/runtime/marshal_jsonpb_test.go index 2d5f8bedd4c..d82290c1416 100644 --- a/runtime/marshal_jsonpb_test.go +++ b/runtime/marshal_jsonpb_test.go @@ -523,6 +523,8 @@ var ( {data: uint64(1), json: "1"}, {data: proto.Uint64(1), json: "1"}, {data: "abc", json: `"abc"`}, + {data: []byte("abc"), json: `"YWJj"`}, + {data: []byte{}, json: `""`}, {data: proto.String("abc"), json: `"abc"`}, {data: float32(1.5), json: "1.5"}, {data: proto.Float32(1.5), json: "1.5"},