if unmarshal target is proto.Message, using jsonpb
This commit is contained in:
parent
5a7113b669
commit
d4d579bd5a
5
codec.go
5
codec.go
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/golang/protobuf/jsonpb"
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
"github.com/micro/go-micro/codec"
|
"github.com/micro/go-micro/codec"
|
||||||
"github.com/micro/go-micro/codec/bytes"
|
"github.com/micro/go-micro/codec/bytes"
|
||||||
@ -79,6 +80,10 @@ func (jsonCodec) Marshal(v interface{}) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (jsonCodec) Unmarshal(data []byte, v interface{}) error {
|
func (jsonCodec) Unmarshal(data []byte, v interface{}) error {
|
||||||
|
if pb, ok := v.(proto.Message); ok {
|
||||||
|
return jsonpb.UnmarshalString(string(data), pb)
|
||||||
|
}
|
||||||
|
|
||||||
return json.Unmarshal(data, v)
|
return json.Unmarshal(data, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user