aboutsummaryrefslogtreecommitdiffhomepage
path: root/csharp/src/Google.Protobuf/JsonParser.cs
diff options
context:
space:
mode:
authorGravatar Jon Skeet <jonskeet@google.com>2016-01-15 13:45:53 +0000
committerGravatar Jon Skeet <jonskeet@google.com>2016-01-15 13:45:53 +0000
commit52db5139c4f122bbd34ef34b4103d0b650e7c218 (patch)
tree09d211be7f7058a9123d0218bd9ab7b4c0302506 /csharp/src/Google.Protobuf/JsonParser.cs
parentf437b67f600545f432863457a39870cb74675d34 (diff)
Change handling of unknown enums: we now write out the value as a number.
Diffstat (limited to 'csharp/src/Google.Protobuf/JsonParser.cs')
-rw-r--r--csharp/src/Google.Protobuf/JsonParser.cs8
1 files changed, 2 insertions, 6 deletions
diff --git a/csharp/src/Google.Protobuf/JsonParser.cs b/csharp/src/Google.Protobuf/JsonParser.cs
index 9e5d8711..92029e06 100644
--- a/csharp/src/Google.Protobuf/JsonParser.cs
+++ b/csharp/src/Google.Protobuf/JsonParser.cs
@@ -617,13 +617,9 @@ namespace Google.Protobuf
return (float) value;
case FieldType.Enum:
CheckInteger(value);
- var enumValue = field.EnumType.FindValueByNumber((int) value);
- if (enumValue == null)
- {
- throw new InvalidProtocolBufferException($"Invalid enum value: {value} for enum type: {field.EnumType.FullName}");
- }
// Just return it as an int, and let the CLR convert it.
- return enumValue.Number;
+ // Note that we deliberately don't check that it's a known value.
+ return (int) value;
default:
throw new InvalidProtocolBufferException($"Unsupported conversion from JSON number for field type {field.FieldType}");
}