aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/Google.Protobuf/JsonFormatter.cs
diff options
context:
space:
mode:
authorJon Skeet <jonskeet@google.com>2016-01-15 13:45:53 +0000
committerJon Skeet <jonskeet@google.com>2016-01-15 13:45:53 +0000
commit52db5139c4f122bbd34ef34b4103d0b650e7c218 (patch)
tree09d211be7f7058a9123d0218bd9ab7b4c0302506 /csharp/src/Google.Protobuf/JsonFormatter.cs
parentf437b67f600545f432863457a39870cb74675d34 (diff)
downloadprotobuf-52db5139c4f122bbd34ef34b4103d0b650e7c218.tar.gz
protobuf-52db5139c4f122bbd34ef34b4103d0b650e7c218.tar.bz2
protobuf-52db5139c4f122bbd34ef34b4103d0b650e7c218.zip
Change handling of unknown enums: we now write out the value as a number.
Diffstat (limited to 'csharp/src/Google.Protobuf/JsonFormatter.cs')
-rw-r--r--csharp/src/Google.Protobuf/JsonFormatter.cs22
1 files changed, 8 insertions, 14 deletions
diff --git a/csharp/src/Google.Protobuf/JsonFormatter.cs b/csharp/src/Google.Protobuf/JsonFormatter.cs
index 573ca766..61961c4c 100644
--- a/csharp/src/Google.Protobuf/JsonFormatter.cs
+++ b/csharp/src/Google.Protobuf/JsonFormatter.cs
@@ -205,11 +205,6 @@ namespace Google.Protobuf
{
continue;
}
- // Omit awkward (single) values such as unknown enum values
- if (!field.IsRepeated && !field.IsMap && !CanWriteSingleValue(value))
- {
- continue;
- }
// Okay, all tests complete: let's write the field value...
if (!first)
@@ -397,7 +392,14 @@ namespace Google.Protobuf
}
else if (value is System.Enum)
{
- WriteString(builder, value.ToString());
+ if (System.Enum.IsDefined(value.GetType(), value))
+ {
+ WriteString(builder, value.ToString());
+ }
+ else
+ {
+ WriteValue(builder, (int) value);
+ }
}
else if (value is float || value is double)
{
@@ -704,10 +706,6 @@ namespace Google.Protobuf
bool first = true;
foreach (var value in list)
{
- if (!CanWriteSingleValue(value))
- {
- continue;
- }
if (!first)
{
builder.Append(PropertySeparator);
@@ -725,10 +723,6 @@ namespace Google.Protobuf
// This will box each pair. Could use IDictionaryEnumerator, but that's ugly in terms of disposal.
foreach (DictionaryEntry pair in dictionary)
{
- if (!CanWriteSingleValue(pair.Value))
- {
- continue;
- }
if (!first)
{
builder.Append(PropertySeparator);