Added convenience methods for to/from xml and json
diff --git a/src/ProtocolBuffers.Test/TestWriterFormatJson.cs b/src/ProtocolBuffers.Test/TestWriterFormatJson.cs
index 88c059d..052d8f2 100644
--- a/src/ProtocolBuffers.Test/TestWriterFormatJson.cs
+++ b/src/ProtocolBuffers.Test/TestWriterFormatJson.cs
@@ -32,6 +32,28 @@
}
[Test]
+ public void TestToJsonParseFromJson()
+ {
+ TestAllTypes msg = new TestAllTypes.Builder().SetDefaultBool(true).Build();
+ string json = msg.ToJson();
+ Assert.AreEqual("{\"default_bool\":true}", json);
+ TestAllTypes copy = TestAllTypes.ParseFromJson(json);
+ Assert.IsTrue(copy.HasDefaultBool && copy.DefaultBool);
+ Assert.AreEqual(msg, copy);
+ }
+
+ [Test]
+ public void TestToJsonParseFromJsonReader()
+ {
+ TestAllTypes msg = new TestAllTypes.Builder().SetDefaultBool(true).Build();
+ string json = msg.ToJson();
+ Assert.AreEqual("{\"default_bool\":true}", json);
+ TestAllTypes copy = TestAllTypes.ParseFromJson(new StringReader(json));
+ Assert.IsTrue(copy.HasDefaultBool && copy.DefaultBool);
+ Assert.AreEqual(msg, copy);
+ }
+
+ [Test]
public void TestJsonFormatted()
{
TestXmlMessage message = TestXmlMessage.CreateBuilder()