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

Enum JsonConverters are not applied #388

Open
vivet opened this issue Apr 26, 2024 · 7 comments
Open

Enum JsonConverters are not applied #388

vivet opened this issue Apr 26, 2024 · 7 comments

Comments

@vivet
Copy link
Owner

vivet commented Apr 26, 2024

The enum converters, e.g. Language enums doesn't hit the default where JsonExceptions are caught returning Unsupported.

@markus-renezeder
Copy link

Is there any update acoording this topic? I ran into this problem today.

Thank you very much for sharing your project!

@vivet
Copy link
Owner Author

vivet commented Oct 31, 2024

Hi

How did you experience the problem?
It should only cause problems if Google adds new languages. Can you see what language it fails on, then I will add that.

I don't have much time at the moment, so I won't get to fix the converters any time soon.

@markus-renezeder
Copy link

I try to serialize the values (e.g. Language or any other enum) for sending it over a rest api.

I get the error message The converter specified on 'GoogleApi.Entities.Common.Enums.AddressComponentType' does not derive from JsonConverter or have a public parameterless constructor..

I will try to find the reason for the problem and maybe I can give you some further information or provide a fix to you.

@vivet
Copy link
Owner Author

vivet commented Oct 31, 2024

Try send me the code that gives issues

@markus-renezeder
Copy link

I created a new .NET Core API project and added just a minimal API method:

app.MapGet("/placeresult", (string id) =>
{
    PlaceResult result = new();

    return result;
})
.WithName("PlaceResult")
.WithOpenApi();

@vivet
Copy link
Owner Author

vivet commented Oct 31, 2024

But there is no code for GoogleApi... I need to see GoogleApi.
It seems your .NET core api is trying to serialize the PlaceResult, which might or might not work. At least you control the serialization of you Api, not GoogleApi.

So basically your issue has nothing to do with GoogleApi, it's wihtin your code.
Generally, you shouldn't expose models from external code directly in your code. After invoking GoogleApi, map the part of the response to your own model that your want to use with the response in your api

@markus-renezeder
Copy link

markus-renezeder commented Oct 31, 2024

You're right. I just want to return the GoogleAPI model and I know I should provide my own model. But that is a lot of work and I wanted to save myself that. The problem is that I have to change a existing project which uses your GoogleAPI to a server / client architecture because the client will not have access to the internet in the near future.

I was able to solve the problem using the following code:

builder.Services.ConfigureHttpJsonOptions(options =>
{
    options.SerializerOptions.Converters.Add(new JsonStringEnumConverter());
});

Thank you for your support and sorry for wasting your time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants