PokeApiNet
PokeApiNet copied to clipboard
JsonSerializationException thrown in PokeClient.GetResourceAsync<Pokemon> for some (mostly Hisuian) Pokémon.
Error converting value {null} to type 'System.Int32'. Path 'base_experience', line 1, position 354.
This probably is caused by the fact these Pokémon have a "base_experience"
with value null
in JSON, which cannot directly be converted to Int32 in C#. Making Pokemon.BaseExperience
nullable will fix it.
To recreate:
Pokemon wyrdeer = await pokeClient.GetResourceAsync<Pokemon>("wyrdeer");
or use any other pokemon where "base_experience": null
.
Thanks for reporting this. Would you like to submit a PR with a fix?
I just noticed the very same problem. If you can find the time, I would greatly appreciate it if you could release a package with the base experience fix.
So sorry for the delay - just published version 3.0.6 with this fix out to nuget that is available now.
Thank you for the quick reply! I didn't mean to rush you. I hope I was not rude.
Unfortunately I have to bug you again :/
I think something went wrong with the nuget push.
The nuget version 3.0.6 seems to still contain the 3.0.5 assembly version and therefore there is still the exception when the serializer tries to parse null
into an integer.
See: https://nuget.info/packages/PokeApiNet/3.0.6
I checked the file hashes, the 3.0.6 and 3.0.5 dlls seem the be the same.
That's what I get for not doing a dotnet clean
beforehand, lol. I just published version 3.0.7 out - this should one has the fix it in. Sorry about that!
Thanks a bunch! The new version is correct now.
Unfortunately there is another issue. :'(
Now base_happiness
of PokemonSpecies
is causing trouble. It's the same problem when the JsonSerializer tries to parse null
into an value type.
I'll do some testing. I'll write an integration test that just gets the Pokemon-Types from the PokeApi.co-API and I'll fix all issues that may be there. Do you want to keep the diskussion in this issue? If not I'll make a new issue with my test results. Unfortunately, I will not be able to finish/start my testing today.
I went through and tested all serialization for all endpoints and I believe I've addressed all of these similar issues in the just-released version 3.0.8.
I ran my test as well.
I found two different issues.
-
base_happiness
may be null (The same issue) [EDIT: solved with version 3.0.8] These are the pokemon that cause issue
❌ wyrdeer - Error converting value {null} to type 'System.Int32'. Path 'base_happiness', line 1, position 22.
❌ kleavor - Error converting value {null} to type 'System.Int32'. Path 'base_happiness', line 1, position 22.
❌ ursaluna - Error converting value {null} to type 'System.Int32'. Path 'base_happiness', line 1, position 22.
❌ basculegion - Error converting value {null} to type 'System.Int32'. Path 'base_happiness', line 1, position 22.
❌ sneasler - Error converting value {null} to type 'System.Int32'. Path 'base_happiness', line 1, position 22.
❌ overqwil - Error converting value {null} to type 'System.Int32'. Path 'base_happiness', line 1, position 22.
❌ enamorus - Error converting value {null} to type 'System.Int32'. Path 'base_happiness', line 1, position 22.
- The language-endpoint uses case-senstive and not "all lower case" identifier strings
❌ ja-Hrkt - Response status code does not indicate success: 404 (Not Found).
❌ zh-Hant - Response status code does not indicate success: 404 (Not Found).
❌ zh-Hans - Response status code does not indicate success: 404 (Not Found).
❌ pt-BR - Response status code does not indicate success: 404 (Not Found).
This is an issue, because the PokeApiClient
(Line 113) converts all letters to lower-case. That's usually fine, however these four languages require upper case letters.
So a request
http GET https://pokeapi.co/api/v2/language/ja-Hrkt Accept:'*/*'
# Status: 200 OK Size: 634 Bytes
gets converted to
http GET https://pokeapi.co/api/v2/language/ja-hrkt Accept:'*/*'
# Status: 404 Not Found Size: 9 Bytes
The fix for the 2nd issue isn't that staight forward.
- Removing the
ToLower
completely would be a breaking change - Adding an exception for the apiEndpoint language seems to be a bit iffy
I'll run my tests vs version 3.0.8 and post my results here as well.
Version 3.0.8 solved the nullable issue. Thanks a bunch for the quick fix. <3
The problem with the language endpoint is still there - but that's a completely different issue.
@FelixDamrau issue with language endpoint should be fixed in latest version
I just saw that I didn't reply here... 🤦♀️ Everything works fine for me now. Thanks a bunch! <3