github.com/gogo/protobuf@v1.3.2/test/jsonpb-gogo/jsonpb_gogo_test.go (about) 1 package jsonpb_gogo 2 3 import ( 4 "testing" 5 6 "github.com/gogo/protobuf/jsonpb" 7 ) 8 9 // customFieldMessage implements protobuf.Message but is not a normal generated message type. 10 type customFieldMessage struct { 11 someField string //this is not a proto field 12 } 13 14 func (m *customFieldMessage) Reset() { 15 m.someField = "hello" 16 } 17 18 func (m *customFieldMessage) String() string { 19 return m.someField 20 } 21 22 func (m *customFieldMessage) ProtoMessage() { 23 } 24 25 func TestUnmarshalWithJSONPBUnmarshaler(t *testing.T) { 26 rawJson := `{}` 27 marshaler := &jsonpb.Marshaler{} 28 msg := &customFieldMessage{someField: "Ignore me"} 29 str, err := marshaler.MarshalToString(msg) 30 if err != nil { 31 t.Errorf("an unexpected error occurred when marshaling message: %v", err) 32 } 33 if str != rawJson { 34 t.Errorf("marshaled JSON was incorrect: got %s, wanted %s", str, rawJson) 35 } 36 }