aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/Google.Protobuf/JsonParser.cs
diff options
context:
space:
mode:
authorJon Skeet <jonskeet@google.com>2016-01-15 14:18:16 +0000
committerJon Skeet <jonskeet@google.com>2016-01-15 14:18:16 +0000
commitb1ea15f7a5480fe946165b0257de4981edca1c82 (patch)
treece1eae7636824d4137c64b2cad8a579d4836eee3 /csharp/src/Google.Protobuf/JsonParser.cs
parent8866d6a80ed30e1ff32f1c5420f1a803c26fa13a (diff)
downloadprotobuf-b1ea15f7a5480fe946165b0257de4981edca1c82.tar.gz
protobuf-b1ea15f7a5480fe946165b0257de4981edca1c82.tar.bz2
protobuf-b1ea15f7a5480fe946165b0257de4981edca1c82.zip
Make sure that
"valueField": null is parsed appropriately, i.e. that it remembers that the field is set.
Diffstat (limited to 'csharp/src/Google.Protobuf/JsonParser.cs')
-rw-r--r--csharp/src/Google.Protobuf/JsonParser.cs21
1 files changed, 17 insertions, 4 deletions
diff --git a/csharp/src/Google.Protobuf/JsonParser.cs b/csharp/src/Google.Protobuf/JsonParser.cs
index b1a24800..c07b16ea 100644
--- a/csharp/src/Google.Protobuf/JsonParser.cs
+++ b/csharp/src/Google.Protobuf/JsonParser.cs
@@ -215,10 +215,15 @@ namespace Google.Protobuf
var token = tokenizer.Next();
if (token.Type == JsonToken.TokenType.Null)
{
+ // Clear the field if we see a null token, unless it's for a singular field of type
+ // google.protobuf.Value.
// Note: different from Java API, which just ignores it.
// TODO: Bring it more in line? Discuss...
- field.Accessor.Clear(message);
- return;
+ if (field.IsMap || field.IsRepeated || !IsGoogleProtobufValueField(field))
+ {
+ field.Accessor.Clear(message);
+ return;
+ }
}
tokenizer.PushBack(token);
@@ -297,14 +302,22 @@ namespace Google.Protobuf
}
}
+ private static bool IsGoogleProtobufValueField(FieldDescriptor field)
+ {
+ return field.FieldType == FieldType.Message &&
+ field.MessageType.FullName == Value.Descriptor.FullName;
+ }
+
private object ParseSingleValue(FieldDescriptor field, JsonTokenizer tokenizer)
{
var token = tokenizer.Next();
if (token.Type == JsonToken.TokenType.Null)
{
- if (field.FieldType == FieldType.Message && field.MessageType.FullName == Value.Descriptor.FullName)
+ // TODO: In order to support dynamic messages, we should really build this up
+ // dynamically.
+ if (IsGoogleProtobufValueField(field))
{
- return new Value { NullValue = NullValue.NULL_VALUE };
+ return Value.ForNull();
}
return null;
}