From 092cc15f9d615850e7580a744deb316ad2175870 Mon Sep 17 00:00:00 2001
From: Manuel <m-allenspach@hotmail.com>
Date: Thu, 30 May 2024 02:20:22 -0700
Subject: [PATCH] Handle groups in C# JsonParser (#16970)

Fixes https://github.com/protocolbuffers/protobuf/issues/16968

Closes #16970

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/16970 from CommonGuy:main b008e189348ea42659b52874a5aaad8857d696ab
PiperOrigin-RevId: 638578696
---
 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?