From b008e189348ea42659b52874a5aaad8857d696ab Mon Sep 17 00:00:00 2001 From: Manuel Allenspach Date: Wed, 29 May 2024 10:50:51 +0200 Subject: [PATCH] Handle groups in C# JsonParser --- csharp/src/Google.Protobuf.Test/JsonParserTest.cs | 10 ++++++++++ csharp/src/Google.Protobuf/JsonParser.cs | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs index ef6d63dbdc..3df906257e 100644 --- a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs +++ b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs @@ -995,6 +995,16 @@ namespace Google.Protobuf Assert.AreEqual(0, parsed.FieldName13); } + [Test] + public void Proto2_Group() + { + string json = "{ \"data\": { \"groupInt32\": 2, \"groupUint32\": 3 } }"; + var parsed = TestAllTypesProto2.Parser.ParseJson(json); + Assert.True(parsed.HasData); + Assert.AreEqual(2, parsed.Data.GroupInt32); + Assert.AreEqual(3, parsed.Data.GroupUint32); + } + [Test] [TestCase("5")] [TestCase("\"text\"")] diff --git a/csharp/src/Google.Protobuf/JsonParser.cs b/csharp/src/Google.Protobuf/JsonParser.cs index 1a0da4a392..fcf859daba 100644 --- a/csharp/src/Google.Protobuf/JsonParser.cs +++ b/csharp/src/Google.Protobuf/JsonParser.cs @@ -330,7 +330,7 @@ namespace Google.Protobuf } var fieldType = field.FieldType; - if (fieldType == FieldType.Message) + if (fieldType == FieldType.Message || fieldType == FieldType.Group) { // Parse wrapper types as their constituent types. // TODO: What does this mean for null?