-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-grpcIncludes: GRPC wire-up, templatesIncludes: GRPC wire-up, templates
Milestone
Description
Edit: Updated with feedback.
Background and Motivation
Many JSON APIs have case insensitive property names. People looking to replace their existing JSON API with gRPC JSON transcoding want to keep that behavior. Today they don't have that option. Some are using reflection to modify JSON settings to enable it.
Addresses #50401
Proposed API
namespace Microsoft.AspNetCore.Grpc.JsonTranscoding;
public sealed class GrpcJsonSettings
{
+ /// <summary>
+ /// Gets or sets a value that indicates whether property names are compared using case-insensitive matching during deserialization.
+ /// The default value is <see langword="false"/>.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// The Protobuf JSON specification requires JSON property names to match field names exactly, including case.
+ /// Enabling this option may reduce interoperability, as case-insensitive matching might not be supported
+ /// by other JSON transcoding implementations.
+ /// </para>
+ /// <para>
+ /// For more information, see <see href="https://protobuf.dev/programming-guides/json/"/>.
+ /// </para>
+ /// </remarks>
+ public bool PropertyNameCaseInsensitive { get; set; }
}
Usage Examples
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddGrpc()
builder.Services.AddJsonTranscoding(o =>
{
o.JsonSettings.FieldNamesCaseInsensitive = true;
});
Alternative Designs
This setting internally sets JsonSerializerOptions.PropertyNameCaseInsensitive
. I considered calling it PropertyNameCaseInsensitive
but in Protobuf members are always called fields, not properties.
Risks
Technically case insensitive property names aren't part of the Protobuf JSON spec - https://protobuf.dev/programming-guides/json/ - but we'll call this out in docs so people can make an informed decision.
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-grpcIncludes: GRPC wire-up, templatesIncludes: GRPC wire-up, templates