Json Unmarshal
Opened this issue · 0 comments
negativeOne1 commented
Hey,
I'm trying to unmarshal some JSON response back into Protobuf.
but I'm getting
json: cannot unmarshal string into Go value of type map[string]json.RawMessage
and it's caused by the ID field
from
s := []byte(`{"id":"5eaacacc6149d0f8d4b6a36d"}`)
var rsp pb.IDMsg
unmarshaler = jsonpb.Unmarshaler{AllowUnknownFields: false}
if err := unmarshaler.Unmarshal(bytes.NewBuffer(s), &rsp); err != nil {
t.Fatal(err)
}
pb.proto:
message IDMsg {
pmongo.ObjectId id = 1;
}
pb.go:
type IDMsg struct {
Id *pmongo.ObjectId `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-" bson:"-"`
XXX_unrecognized []byte `json:"-" bson:"-"`
XXX_sizecache int32 `json:"-" bson:"-"`
}