iluvadev / PocketBaseClient

C# client to interact with a particular PocketBase application: an ORM mapped to your PocketBase server. [This project is in active development. The things described below could change]
MIT License
43 stars 8 forks source link

Fix invalid JSON deserialization in v0.6.0 #34

Closed mtaku3 closed 1 year ago

mtaku3 commented 1 year ago

This PR includes a fix of two issues.

The first issue

The first issue is a invalid JSON deserialization of PocketBaseExtensions.Send<T>. In previous version, PocketBaseClient was using pocketbase-csharp-sdk's SendAsync method. But in v0.6.0, it seems like you have migrated from it to PocketBaseExtensions. PocketBaseExtensions.Send uses System.Text.Json's JSON deserializer, which is case sensitive by default. But pocketbase-csharp-sdk is using HttpClient's method in order to deserialize, so that JSON deserializer uses case-insensitive option. What we need to add is JSON serialization options of case-insensitive to JSON deserializer. I used JsonSerializerDefaults.Web rather than creating our own serializer options. Because pocketbase-csharp-sdk is based on this options according to this article.

The second issue

I found that my previous PR about invalid json deserialization wasn't fully fixed. The main cause of it is AddInternal is being called before all fields of a item being set. I'll explain in comments line by line. So please reference to that.

iluvadev commented 1 year ago

Thanks a lot. I see, you are right, sorry I think I rushed with the last changes I made. About the first issue: is caused by the need of a double implementation for async and sync methods in order to avoid async to sync conversions:

Again thanks!