You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using JikanDotNet;varjikan=new Jikan();try{_=await jikan.GetUserMangaListAsync("N0D4N");//_ = await jikan.GetUserAnimeListAsync("N0D4N");}catch(Exceptionex){
Console.WriteLine(ex);}
Exception
JikanDotNet.Exceptions.JikanRequestException: Serialization failed.
Inner exception message: The JSON value could not be converted to System.String. Path: $.data[0].reading_status | LineNumber: 0 | BytePositionInLine: 28.
---> System.Text.Json.JsonException: The JSON value could not be converted to System.String. Path: $.data[0].reading_status | LineNumber: 0 | BytePositionInLine: 28.
---> System.InvalidOperationException: Cannot get the value of a token type 'Number' as a string.
at System.Text.Json.Utf8JsonReader.GetString()
at System.Text.Json.Serialization.Converters.StringConverter.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader)
at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
at System.Text.Json.Serialization.JsonCollectionConverter`2.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, TCollection& value)
at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader)
at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
--- End of inner exception stack trace ---
at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, Utf8JsonReader& reader, Exception ex)
at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 utf8Json, JsonTypeInfo jsonTypeInfo, Nullable`1 actualByteCount)
at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 json, JsonTypeInfo jsonTypeInfo)
at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)
at JikanDotNet.Jikan.ExecuteGetRequestAsync[T](ICollection`1 routeSections)
--- End of inner exception stack trace ---
at JikanDotNet.Jikan.ExecuteGetRequestAsync[T](ICollection`1 routeSections)
at JikanDotNet.Jikan.GetUserMangaListAsync(String username)
at Program.<Main>$(String[] args)
Jikan response for https://api.jikan.moe/v4/users/N0D4N/mangalist
Seems like System.Text.Json doesn't convert json number value to string automatically, which is ReadingStatus/WatchingStatus of MangaListEntry/AnimeListEntry. Unfortunately JsonSerializerOptions doesn't have option to allow getting string from json's number, one way to fix it would be to write custom JsonConverter that will allow it, another is to change properties type from string to int/enum
The text was updated successfully, but these errors were encountered:
Huh, interesting. I recall the status was changed from enum/int to string during switch API version 3 to 4, but maybe it was not intended and then it was reverted.
Repro
.NET6, JikanDotNet v2.1.0
Exception
Jikan response for
https://api.jikan.moe/v4/users/N0D4N/mangalist
Notes
Seems like System.Text.Json doesn't convert json number value to string automatically, which is
ReadingStatus
/WatchingStatus
ofMangaListEntry
/AnimeListEntry
. UnfortunatelyJsonSerializerOptions
doesn't have option to allow getting string from json's number, one way to fix it would be to write customJsonConverter
that will allow it, another is to change properties type from string toint
/enum
The text was updated successfully, but these errors were encountered: