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

Exception while trying to get user's manga/anime list #35

Closed
N0D4N opened this issue Apr 17, 2022 · 3 comments
Closed

Exception while trying to get user's manga/anime list #35

N0D4N opened this issue Apr 17, 2022 · 3 comments

Comments

@N0D4N
Copy link
Contributor

N0D4N commented Apr 17, 2022

Repro

.NET6, JikanDotNet v2.1.0

using JikanDotNet;

var jikan = new Jikan();
try
{
	_ = await jikan.GetUserMangaListAsync("N0D4N");
	//_ = await jikan.GetUserAnimeListAsync("N0D4N");
}
catch (Exception ex)
{
	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

{
  "data": [
    {
      "reading_status": 1,
      "score": 0,
      // everything else

Notes

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

@Ervie
Copy link
Owner

Ervie commented Apr 17, 2022

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.

I'll add the enum back.

@Ervie
Copy link
Owner

Ervie commented Apr 17, 2022

It was fixed and pushed as version 2.1.1, which should appear within next hour on nuget.

@N0D4N
Copy link
Contributor Author

N0D4N commented Apr 18, 2022

Works as expected, thanks for the fix

@N0D4N N0D4N closed this as completed Apr 18, 2022
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