Search code examples
protocol-buffersgrpc

ProtoBuf Unmarshal JSON into Timestamp


Trying to see if something like this exists:

message TimestampedThing {

    string thing = 1;
    Timestamp date = 2 (layout="2018-03-07T01:00:00.000Z");
}

Getting a parse error when I unmarshal it into the GRPC object.

details: 'json: cannot unmarshal string into Go struct field TimestampedThing.createdTimestamp of type timestamp.Timestamp'


Solution

  • Turns out I needed jsonpb: https://godoc.org/github.com/golang/protobuf/jsonpb

    jsonpb.Unmarshal(bufio.NewReader(bytes), &pb.TimestampedThing)