Skip to content

Commit

Permalink
Merge pull request #208 from sriniven/jsonunmarshal
Browse files Browse the repository at this point in the history
Allowing unknown fields to be dropped instead of returning error from…
  • Loading branch information
yugui authored Aug 8, 2016
2 parents c8ec92d + 22f58cf commit ccd4e6b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions runtime/marshal_jsonpb.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ func decodeJSONPb(d *json.Decoder, v interface{}) error {
if !ok {
return decodeNonProtoField(d, v)
}
return jsonpb.UnmarshalNext(d, p)
unmarshaler := &jsonpb.Unmarshaler{AllowUnknownFields: true}
return unmarshaler.UnmarshalNext(d, p)
}

func decodeNonProtoField(d *json.Decoder, v interface{}) error {
Expand All @@ -124,7 +125,8 @@ func decodeNonProtoField(d *json.Decoder, v interface{}) error {
rv.Set(reflect.New(rv.Type().Elem()))
}
if rv.Type().ConvertibleTo(typeProtoMessage) {
return jsonpb.UnmarshalNext(d, rv.Interface().(proto.Message))
unmarshaler := &jsonpb.Unmarshaler{AllowUnknownFields: true}
return unmarshaler.UnmarshalNext(d, rv.Interface().(proto.Message))
}
rv = rv.Elem()
}
Expand Down

0 comments on commit ccd4e6b

Please sign in to comment.