-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Closed
Labels
area-grpcIncludes: GRPC wire-up, templatesIncludes: GRPC wire-up, templatesdesign-proposalThis issue represents a design proposal for a different issue, linked in the descriptionThis issue represents a design proposal for a different issue, linked in the description
Description
Summary
Allow to use custom JsonConverter
in gRPC JSON transcoding.
Motivation and goals
Motivation
- There is no
decimal
(for example) in protobuf well-known types; - You implement your own (https://learn.microsoft.com/en-us/dotnet/architecture/grpc-for-wcf-developers/protobuf-data-types#decimals);
- It work flawless via gRPC;
- But in REST API you now have
units
andnanos
instead ofdecimal
; - You fixed Swagger documentation via
MapType
; - You write custom
JsonConverter
for REST API; - You can't use it.
Because of the last point all REST API consumers must write wrappers for decimal
or you must use string
for decimal
.
Goals
Add JsonConverter
support for gRPC JSON transcoding.
Valuabiity
- 28k downloads of https://www.nuget.org/packages/Microsoft.AspNetCore.Grpc.JsonTranscoding;
decimal
implementation is a common issue which is solved via custom type Decimal Type? protocolbuffers/protobuf#4406;Guid
also Provide support for UUID type (a.k.a. GUID) protocolbuffers/protobuf#2224;- Potentially there are more situations when you need a gRPC-BCL type implicitly mapping;
- Developers use different JSON serialization on purpose https://thomaslevesque.com/2020/06/27/exposing-custom-type-as-json-string-in-asp-net-core-api/;
grpc-gateway
supports custom marshalers Response body as a single field grpc-ecosystem/grpc-gateway#217.
In scope
- As a developer I want to implement custom JsonConverter for gRPC JSON transcoding.
- As a developer I want that gRPC and JSON types could have a different representation for the same .NET type.
Out of scope
–
Risks / unknowns
Risks
–
Unknowns
@JamesNK explicitly wrote in gRPC JSON transcoding documentation:
Transcoding doesn't support advanced JSON customization. Apps requiring precise JSON structure control should consider using ASP.NET Core Web API.
https://learn.microsoft.com/en-us/aspnet/core/grpc/json-transcoding-binding?view=aspnetcore-7.0#customize-json
I haven't found decision clarification for this behaviour.
Examples
- When you
AddJsonTranscoding
there could be a propertyConverters
where you can add your ownJsonConverter
like inJsonSerializerOptions
; - gRPC JSON transcoding also could look for
JsonConverter
attribute on a not well-known types.
m3nax, heggi, wookieeapps, alrz, LeleDerGrasshalmi and 3 more
Metadata
Metadata
Assignees
Labels
area-grpcIncludes: GRPC wire-up, templatesIncludes: GRPC wire-up, templatesdesign-proposalThis issue represents a design proposal for a different issue, linked in the descriptionThis issue represents a design proposal for a different issue, linked in the description