diff options
author | Jon Skeet <jonskeet@google.com> | 2015-07-20 11:48:24 +0100 |
---|---|---|
committer | Jon Skeet <jonskeet@google.com> | 2015-07-20 11:48:24 +0100 |
commit | c9fd53a3b742f2a34c527cbe0833c5bc081e6ec3 (patch) | |
tree | 410dee597653917b53ff1d7646b92deb5b15ffda /csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs | |
parent | 3f5df7a74b9d6989d0ea0cb0664f0105d80767eb (diff) | |
download | protobuf-c9fd53a3b742f2a34c527cbe0833c5bc081e6ec3.tar.gz protobuf-c9fd53a3b742f2a34c527cbe0833c5bc081e6ec3.tar.bz2 protobuf-c9fd53a3b742f2a34c527cbe0833c5bc081e6ec3.zip |
First part of JSON formatting for well-known types. I think we need a reflection API rethink before doing the rest.
Diffstat (limited to 'csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs')
-rw-r--r-- | csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs b/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs index 5441bf47..a6715698 100644 --- a/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs +++ b/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs @@ -257,5 +257,32 @@ namespace Google.Protobuf formatter = new JsonFormatter(new JsonFormatter.Settings(true)); Assert.AreEqual(expectedJson, formatter.Format(message)); } + + [Test] + public void WrapperFormatting_Single() + { + // Just a few examples, handling both classes and value types, and + // default vs non-default values + var message = new TestWellKnownTypes + { + Int64Field = 10, + Int32Field = 0, + BytesField = ByteString.FromBase64("ABCD"), + StringField = "" + }; + var expectedJson = "{ \"int64Field\": \"10\", \"int32Field\": 0, \"stringField\": \"\", \"bytesField\": \"ABCD\" }"; + Assert.AreEqual(expectedJson, JsonFormatter.Default.Format(message)); + } + + [Test] + public void WrapperFormatting_IncludeNull() + { + // The actual JSON here is very large because there are lots of fields. Just test a couple of them. + var message = new TestWellKnownTypes { Int32Field = 10 }; + var formatter = new JsonFormatter(new JsonFormatter.Settings(true)); + var actualJson = formatter.Format(message); + Assert.IsTrue(actualJson.Contains("\"int64Field\": null")); + Assert.IsFalse(actualJson.Contains("\"int32Field\": null")); + } } } |