From fb2488225fbd239f7880e3b493cbfd2f19da755b Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Fri, 4 Sep 2015 12:41:14 +0100 Subject: Implement JSON parsing in C#. This includes all the well-known types except Any. Some aspects are likely to require further work when the details of the JSON parsing expectations are hammered out in more detail. Some of these have "ignored" tests already. Note that the choice *not* to use Json.NET was made for two reasons: - Going from 0 dependencies to 1 dependency is a big hit, and there's not much benefit here - Json.NET parses more leniently than we'd want; accommodating that would be nearly as much work as writing the tokenizer This only really affects the JsonTokenizer, which could be replaced by Json.NET. The JsonParser code would be about the same length with Json.NET... but I wouldn't be as confident in it. --- csharp/src/Google.Protobuf/MessageParser.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'csharp/src/Google.Protobuf/MessageParser.cs') diff --git a/csharp/src/Google.Protobuf/MessageParser.cs b/csharp/src/Google.Protobuf/MessageParser.cs index 6a6f1017..70c52ba6 100644 --- a/csharp/src/Google.Protobuf/MessageParser.cs +++ b/csharp/src/Google.Protobuf/MessageParser.cs @@ -142,5 +142,17 @@ namespace Google.Protobuf message.MergeFrom(input); return message; } + + /// + /// Parses a message from the given JSON. + /// + /// The JSON to parse. + /// The parsed message. + public T ParseJson(string json) + { + T message = factory(); + JsonParser.Default.Merge(message, json); + return message; + } } } -- cgit v1.2.3