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

JsonSerializationException when calling TvDbClient.SeriesExtended() and data.averageRuntime is null #34

Open
snew3687 opened this issue Nov 11, 2022 · 3 comments · May be fixed by #35
Open

Comments

@snew3687
Copy link

For some TV series, a JsonSerializationException occurs when calling TvDbClient.SeriesExtended() because the averageRuntime is null.

For example, this request:
https://api4.thetvdb.com/v4/series/402602/extended

...returns a response including the following:

{
        "isOrderRandomized": false,
        "lastUpdated": "2022-11-11 07:43:55",
        "averageRuntime": null,
}

It seems to me that TvDbSharper.SeriesExtendedRecordDto.AverageRuntime needs to be of type int? rather than int.

I thought about submitting a pull request (which I have never done before). However, it appears that this class is generated code...so, applying a manual fix seems not to be the right thing to do. I am guessing that the class needs be regenerated, in some way.

I am guessing that this code is generated from the the TVDB API's JSON schema, like here:
https://thetvdb.github.io/v4-api/#/Series/getSeriesExtended

I don't know much about JSON schema...the schema indicates that averageRuntime is an int. I don't know how we are supposed to know that this may be nullable.

Anyway, I hope it is useful that I have raised this issue because the issue results in the following exception for my code:

Newtonsoft.Json.JsonSerializationException
  HResult=0x80131500
  Message=Error converting value {null} to type 'System.Int32'. Path 'data.averageRuntime', line 1, position 617.
  Source=Newtonsoft.Json
  StackTrace:
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at TvDbSharper.TvDbClient.Parse[T](Int32 statusCode, String responseJson)
   at TvDbSharper.TvDbClient.<Get>d__12`1.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Picks03a.Database.Repository.TheTvDbReferenceRepository.<GetTvSeriesAsync>d__7.MoveNext() in C:\gitrepos\picks03c-webapi\src\Picks03a.Database\Repository\TheTvDbReferenceRepository.cs:line 85
@snew3687
Copy link
Author

This issue has been occurring for me for the last several days. Then, today, I tried again, and it is no longer occurring. At least not for television series with id "402602". When I retry a GET of this URL, now:
https://api4.thetvdb.com/v4/series/402602/extended

...the result includes a non-null averageRuntime value, like so:

{
       ...
        "isOrderRandomized": false,
        "lastUpdated": "2022-11-11 21:10:54",
        "averageRuntime": 52,
        "episodes": null,
       ...

}

So, perhaps this not a TvDBSharper issue at all? Perhaps it was a (temporary) issue in the TVDB API itself, and has been resolved?

Or perhaps the issue still exists...but the data has been corrected for this record? I'm not sure how to tell.

@snew3687
Copy link
Author

OK, I have had a closer look at this now. I can see how the code generator works. It seems to me that SeriesExtendedRecordDto.AverageRuntime needs to be nullable. I have created a pull request #35 to fix this issue.

However, the AppVeyer continues build seems to have failed and has blocked my pull request:
https://ci.appveyor.com/project/HristoKolev/tvdbsharper/builds/45359103

Seems to be an issue related to the .NET version, which I don't believe to be a result of the code change that I made. So I'm not sure how to progress this now.

@HristoKolev
Copy link
Owner

Hi there. I had a busy couple of months and kind of neglected this project. I'll take a look at this in the coming days.

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

Successfully merging a pull request may close this issue.

2 participants