aboutsummaryrefslogtreecommitdiffhomepage
path: root/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs
diff options
context:
space:
mode:
authorGravatar Jon Skeet <jonskeet@google.com>2015-07-31 15:07:50 +0100
committerGravatar Jon Skeet <jonskeet@google.com>2015-08-03 09:32:36 +0100
commite7caf15577e4fc8a024403bd8586041742d9e266 (patch)
treebad3eece629af358c2e808e26073c301524aa312 /csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs
parent115e6c735ec561d5260c134fa74ee0d5121a441b (diff)
Initial pass at formatting Struct as JSON.
This seems remarkably little code, but it appears to work. I can add tests for invalid structs at some point, once the general approach is approved.
Diffstat (limited to 'csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs')
-rw-r--r--csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs17
1 files changed, 17 insertions, 0 deletions
diff --git a/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs b/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs
index 82094ea3..f6e6488f 100644
--- a/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs
+++ b/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs
@@ -368,7 +368,24 @@ namespace Google.Protobuf
{
var message = new TestWellKnownTypes { DurationField = new Duration() };
AssertJson("{ 'durationField': '0s' }", JsonFormatter.Default.Format(message));
+ }
+ [Test]
+ public void StructSample()
+ {
+ var message = new Struct
+ {
+ Fields =
+ {
+ { "a", new Value { NullValue = new NullValue() } },
+ { "b", new Value { BoolValue = false } },
+ { "c", new Value { NumberValue = 10.5 } },
+ { "d", new Value { StringValue = "text" } },
+ { "e", new Value { ListValue = new ListValue { Values = { new Value { StringValue = "t1" }, new Value { NumberValue = 5 } } } } },
+ { "f", new Value { StructValue = new Struct { Fields = { { "nested", new Value { StringValue = "value" } } } } } }
+ }
+ };
+ AssertJson("{ 'a': null, 'b': false, 'c': 10.5, 'd': 'text', 'e': [ 't1', 5 ], 'f': { 'nested': 'value' } }", message.ToString());
}
/// <summary>