Skip to content

[release/8.0] Fix reading null struct property value in gRPC JSON transcoding #52469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace Microsoft.AspNetCore.Grpc.JsonTranscoding.Internal.Json;

internal sealed class ValueConverter<TMessage> : SettingsConverterBase<TMessage> where TMessage : IMessage, new()
{
public override bool HandleNull => true;

public ValueConverter(JsonContext context) : base(context)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,46 @@ public void RepeatedStrings()
AssertReadJson<HelloRequest>(json);
}

[Fact]
public void Struct_NullProperty()
{
var json = @"{ ""prop"": null }";

AssertReadJson<Struct>(json);
}

[Fact]
public void Value_Null()
{
var json = "null";

AssertReadJson<Value>(json);
}

[Fact]
public void Value_Integer()
{
var json = "1";

AssertReadJson<Value>(json);
}

[Fact]
public void Value_String()
{
var json = @"""string!""";

AssertReadJson<Value>(json);
}

[Fact]
public void Value_Boolean()
{
var json = "true";

AssertReadJson<Value>(json);
}

[Fact]
public void DataTypes_DefaultValues()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,23 @@ public void Value_Nested()
AssertWrittenJson(helloRequest);
}

[Fact]
public void Struct_NullValue()
{
var helloRequest = new HelloRequest
{
ValueValue = Value.ForStruct(new Struct
{
Fields =
{
["prop"] = Value.ForNull()
}
})
};

AssertWrittenJson(helloRequest);
}

[Fact]
public void Value_Root()
{
Expand All @@ -351,6 +368,14 @@ public void Value_Root()
AssertWrittenJson(value);
}

[Fact]
public void Value_Null()
{
var value = Value.ForNull();

AssertWrittenJson(value);
}

[Fact]
public void Struct_Nested()
{
Expand Down