aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/Google.Protobuf.Test/IssuesTest.cs
diff options
context:
space:
mode:
authorJon Skeet <skeet@pobox.com>2016-03-30 09:11:59 +0100
committerJon Skeet <skeet@pobox.com>2016-03-30 09:11:59 +0100
commit261fde17072075eb69be1acdd58f4a97986465e0 (patch)
treee946d75326662d0e2f72a4379de098fa61c25705 /csharp/src/Google.Protobuf.Test/IssuesTest.cs
parent261ee021f640ea6fe67aaf1f53e1518ed154cad0 (diff)
parentaf34538aca9d91b86826223624018a69370caa1d (diff)
downloadprotobuf-261fde17072075eb69be1acdd58f4a97986465e0.tar.gz
protobuf-261fde17072075eb69be1acdd58f4a97986465e0.tar.bz2
protobuf-261fde17072075eb69be1acdd58f4a97986465e0.zip
Merge pull request #1326 from the-alien/csharp_json_name
csharp: add support for the json_name option
Diffstat (limited to 'csharp/src/Google.Protobuf.Test/IssuesTest.cs')
-rw-r--r--csharp/src/Google.Protobuf.Test/IssuesTest.cs19
1 files changed, 19 insertions, 0 deletions
diff --git a/csharp/src/Google.Protobuf.Test/IssuesTest.cs b/csharp/src/Google.Protobuf.Test/IssuesTest.cs
index a0350035..a38d6b08 100644
--- a/csharp/src/Google.Protobuf.Test/IssuesTest.cs
+++ b/csharp/src/Google.Protobuf.Test/IssuesTest.cs
@@ -59,5 +59,24 @@ namespace Google.Protobuf
// Underscores aren't reflected in the JSON.
Assert.AreEqual("{ \"types\": 10, \"descriptor\": 20 }", message.ToString());
}
+
+ [Test]
+ public void JsonNameParseTest()
+ {
+ var settings = new JsonParser.Settings(10, TypeRegistry.FromFiles(UnittestIssuesReflection.Descriptor));
+ var parser = new JsonParser(settings);
+
+ // It is safe to use either original field name or explicitly specified json_name
+ Assert.AreEqual(new TestJsonName { Name = "test", Description = "test2", Guid = "test3" },
+ parser.Parse<TestJsonName>("{ \"name\": \"test\", \"desc\": \"test2\", \"guid\": \"test3\" }"));
+ }
+
+ [Test]
+ public void JsonNameFormatTest()
+ {
+ var message = new TestJsonName { Name = "test", Description = "test2", Guid = "test3" };
+ Assert.AreEqual("{ \"name\": \"test\", \"desc\": \"test2\", \"exid\": \"test3\" }",
+ JsonFormatter.Default.Format(message));
+ }
}
}