Skip to content
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

gRPC JSON transcoding / Support custom JsonConverter #46712

Open
colotiline opened this issue Feb 16, 2023 · 5 comments
Open

gRPC JSON transcoding / Support custom JsonConverter #46712

colotiline opened this issue Feb 16, 2023 · 5 comments
Labels
area-grpc Includes: GRPC wire-up, templates design-proposal This issue represents a design proposal for a different issue, linked in the description

Comments

@colotiline
Copy link

colotiline commented Feb 16, 2023

Summary

Allow to use custom JsonConverter in gRPC JSON transcoding.

Motivation and goals

Motivation

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

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 property Converters where you can add your own JsonConverter like in JsonSerializerOptions;
  • gRPC JSON transcoding also could look for JsonConverter attribute on a not well-known types.
@colotiline colotiline added the design-proposal This issue represents a design proposal for a different issue, linked in the description label Feb 16, 2023
@mkArtakMSFT mkArtakMSFT added the area-grpc Includes: GRPC wire-up, templates label Feb 20, 2023
@LukaszRacon
Copy link

In case someone is interested in a workaround: #50401 (comment)

@vpetryaev
Copy link

In case someone is interested in a workaround: #50401 (comment)

This workaround not working with custom converters. Exception appear, after registering custom converter using reflection:
System.InvalidOperationException: Invalid JsonTypeInfo operation for JsonTypeInfoKind 'None'.

@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
@aspmaker
Copy link

In case someone is interested in a workaround: #50401 (comment)

This workaround not working with custom converters. Exception appear, after registering custom converter using reflection:
System.InvalidOperationException: Invalid JsonTypeInfo operation for JsonTypeInfoKind 'None'.

hello, did you find a solution for that? i can not cast Google.Protobuf.WellKnownTypes.

i get this error :

Exception was thrown by handler. InvalidCastException: Unable to cast object of type 'Google.Protobuf.WellKnownTypes.StringValue' to type 'System.String'.

thank you.

@vpetryaev
Copy link

vpetryaev commented Apr 19, 2024

i get this error :

Exception was thrown by handler. InvalidCastException: Unable to cast object of type 'Google.Protobuf.WellKnownTypes.StringValue' to type 'System.String'.

Are you sure, that you specify 'string?' (nullable)?

@aspmaker
Copy link

i get this error :

Exception was thrown by handler. InvalidCastException: Unable to cast object of type 'Google.Protobuf.WellKnownTypes.StringValue' to type 'System.String'.

Are you sure, that you specify 'string?' (nullable)?

i created new issue :
#55254

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-grpc Includes: GRPC wire-up, templates design-proposal This issue represents a design proposal for a different issue, linked in the description
Projects
None yet
Development

No branches or pull requests

7 participants
@LukaszRacon @colotiline @wtgodbe @aspmaker @vpetryaev @mkArtakMSFT and others