diff --git a/grpc/testdata/wrappers_testing/service.go b/grpc/testdata/wrappers_testing/service.go index ed44777..52e38e0 100644 --- a/grpc/testdata/wrappers_testing/service.go +++ b/grpc/testdata/wrappers_testing/service.go @@ -53,7 +53,7 @@ func (s *service) TestBoolean(ctx context.Context, in *wrappers.BoolValue) (*wra } func (s *service) TestDouble(ctx context.Context, in *wrappers.DoubleValue) (*wrappers.DoubleValue, error) { - if s.TestBooleanImplementation != nil { + if s.TestDoubleImplementation != nil { return s.TestDoubleImplementation(ctx, in) } diff --git a/lib/netext/grpcext/conn.go b/lib/netext/grpcext/conn.go index d2d382d..5e9f9e0 100644 --- a/lib/netext/grpcext/conn.go +++ b/lib/netext/grpcext/conn.go @@ -154,23 +154,11 @@ func (c *Conn) Invoke( } if resp != nil { - // (rogchap) there is a lot of marshaling/unmarshaling here, but if we just pass the dynamic message - // the default Marshaller would be used, which would strip any zero/default values from the JSON. - // eg. given this message: - // message Point { - // double x = 1; - // double y = 2; - // double z = 3; - // } - // and a value like this: - // msg := Point{X: 6, Y: 4, Z: 0} - // would result in JSON output: - // {"x":6,"y":4} - // rather than the desired: - // {"x":6,"y":4,"z":0} - raw, _ := marshaler.Marshal(resp) - var msg interface{} - _ = json.Unmarshal(raw, &msg) + msg, err := convert(marshaler, resp) + if err != nil { + return nil, fmt.Errorf("unable to convert response object to JSON: %w", err) + } + response.Message = msg } return &response, nil diff --git a/lib/netext/grpcext/stream.go b/lib/netext/grpcext/stream.go index ac9e567..681a990 100644 --- a/lib/netext/grpcext/stream.go +++ b/lib/netext/grpcext/stream.go @@ -35,7 +35,7 @@ func (s *Stream) ReceiveConverted() (interface{}, error) { return nil, err } - msg, errConv := s.convert(raw) + msg, errConv := convert(s.marshaler, raw) if errConv != nil { return nil, errConv } @@ -78,10 +78,10 @@ func (s *Stream) receive() (*dynamicpb.Message, error) { // {"x":6,"y":4} // rather than the desired: // {"x":6,"y":4,"z":0} -func (s *Stream) convert(msg *dynamicpb.Message) (interface{}, error) { +func convert(marshaler protojson.MarshalOptions, msg *dynamicpb.Message) (interface{}, error) { // TODO(olegbespalov): add the test that checks that message is not nil - raw, err := s.marshaler.Marshal(msg) + raw, err := marshaler.Marshal(msg) if err != nil { return nil, fmt.Errorf("failed to marshal the message: %w", err) }