crowdin / crowdin-api-client-dotnet

.NET client library for Crowdin API
https://www.nuget.org/packages/Crowdin.Api/
MIT License
53 stars 26 forks source link

tmPenalties is an array when blank (should be object) #247

Closed yevheniilavrenchuk closed 3 months ago

yevheniilavrenchuk commented 3 months ago

We are using the latest API released - 2.23.1 image

When Penalties are not filled in the Project settings, then in the API response it is an array:

image

image

But in API it is object: image

When the request is made by the application, the error is thrown:

System.AggregateException: 'One or more errors occurred. (Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'Crowdin.Api.ProjectsGroups.TmPenalties' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
andrii-bodnar commented 3 months ago

This is a common thing for the API response when it returns an empty array (on the API side there is no difference between an empty object and an empty array).

We already have EmptyArrayAsObjectConverter in this client. This should probably be used in the TmPenalties case as well.

@innomaxx what do you think?

innomaxx commented 3 months ago

This is a common thing for the API response when it returns an empty array (on the API side there is no difference between an empty object and an empty array).

We already have EmptyArrayAsObjectConverter in this client. This should probably be used in the TmPenalties case as well.

@innomaxx what do you think?

Yes, we can try fix it via custom converter, like in other similar cases, but it's a workaround rather than a long-term solution. I still recommend fix it API-widely on the Crowdin Backend side (if possible).

andrii-bodnar commented 3 months ago

Unfortunately, there is no quick general fix for the API. Each case should be fixed individually. It will take a lot of time to fix it (creating a task, scheduling, reaching the sprint, etc), so it would be better to fix it on the API client side using the custom converter.

innomaxx commented 3 months ago

Ok I'll handle it until asap

andrii-bodnar commented 3 months ago

@yevheniilavrenchuk available in 2.24.0

yevheniilavrenchuk commented 3 months ago

@yevheniilavrenchuk available in 2.24.0

Thanks, it works like a charm!