Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json Unmarshal #4

Open
negativeOne1 opened this issue Apr 30, 2020 · 0 comments
Open

Json Unmarshal #4

negativeOne1 opened this issue Apr 30, 2020 · 0 comments

Comments

@negativeOne1
Copy link

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:"-"`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant