Skip to content

Commit 0e9dd4c

Browse files
CommonGuyzhangskz
authored andcommitted
Handle groups in C# JsonParser (#16970)
Fixes #16968 Closes #16970 COPYBARA_INTEGRATE_REVIEW=#16970 from CommonGuy:main b008e18 PiperOrigin-RevId: 638578696
1 parent 838626d commit 0e9dd4c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

csharp/src/Google.Protobuf.Test/JsonParserTest.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,16 @@ public void Proto2_DefaultValuesPreserved()
995995
Assert.AreEqual(0, parsed.FieldName13);
996996
}
997997

998+
[Test]
999+
public void Proto2_Group()
1000+
{
1001+
string json = "{ \"data\": { \"groupInt32\": 2, \"groupUint32\": 3 } }";
1002+
var parsed = TestAllTypesProto2.Parser.ParseJson(json);
1003+
Assert.True(parsed.HasData);
1004+
Assert.AreEqual(2, parsed.Data.GroupInt32);
1005+
Assert.AreEqual(3, parsed.Data.GroupUint32);
1006+
}
1007+
9981008
[Test]
9991009
[TestCase("5")]
10001010
[TestCase("\"text\"")]

csharp/src/Google.Protobuf/JsonParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ private bool TryParseSingleValue(FieldDescriptor field, JsonTokenizer tokenizer,
330330
}
331331

332332
var fieldType = field.FieldType;
333-
if (fieldType == FieldType.Message)
333+
if (fieldType == FieldType.Message || fieldType == FieldType.Group)
334334
{
335335
// Parse wrapper types as their constituent types.
336336
// TODO: What does this mean for null?

0 commit comments

Comments
 (0)