fix default behavior for gRPC encoding (#2187)

Co-authored-by: chenzhihui <chenzhihui@bilibili.com>
pull/2217/head
Tony Chen 2 years ago committed by GitHub
parent e6767bc612
commit 3c54997dd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      transport/grpc/codec.go

@ -3,6 +3,7 @@ package grpc
import (
"fmt"
enc "github.com/go-kratos/kratos/v2/encoding"
"github.com/go-kratos/kratos/v2/encoding/json"
"google.golang.org/grpc/encoding"
"google.golang.org/protobuf/proto"
@ -20,7 +21,7 @@ func (codec) Marshal(v interface{}) ([]byte, error) {
if !ok {
return nil, fmt.Errorf("failed to marshal, message is %T, want proto.Message", v)
}
return json.MarshalOptions.Marshal(vv)
return enc.GetCodec(json.Name).Marshal(vv)
}
func (codec) Unmarshal(data []byte, v interface{}) error {
@ -28,9 +29,9 @@ func (codec) Unmarshal(data []byte, v interface{}) error {
if !ok {
return fmt.Errorf("failed to unmarshal, message is %T, want proto.Message", v)
}
return json.UnmarshalOptions.Unmarshal(data, vv)
return enc.GetCodec(json.Name).Unmarshal(data, vv)
}
func (codec) Name() string {
return "json"
return json.Name
}

Loading…
Cancel
Save