Skip to content

Commit

Permalink
Handle groups in C# JsonParser (#16970)
Browse files Browse the repository at this point in the history
Fixes #16968

Closes #16970

COPYBARA_INTEGRATE_REVIEW=#16970 from CommonGuy:main b008e18
PiperOrigin-RevId: 638578696
  • Loading branch information
CommonGuy authored and Copybara-Service committed May 30, 2024
1 parent 89c27bf commit 092cc15
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions csharp/src/Google.Protobuf.Test/JsonParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,16 @@ public void Proto2_DefaultValuesPreserved()
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\"")]
Expand Down
2 changes: 1 addition & 1 deletion csharp/src/Google.Protobuf/JsonParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ private bool TryParseSingleValue(FieldDescriptor field, JsonTokenizer tokenizer,
}

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?
Expand Down

0 comments on commit 092cc15

Please sign in to comment.