Handle seasons with a "null" air date #175
@@ -21,8 +21,9 @@ namespace Jellyfin.Xtream.Client.Models;
|
|||||||
|
|
||||||
public class Season
|
public class Season
|
||||||
{
|
{
|
||||||
|
[JsonConverter(typeof(NullStringDateTimeConverter))]
|
||||||
[JsonProperty("air_date")]
|
[JsonProperty("air_date")]
|
||||||
public DateTime AirDate { get; set; }
|
public DateTime? AirDate { get; set; }
|
||||||
|
|
||||||
[JsonProperty("episode_count")]
|
[JsonProperty("episode_count")]
|
||||||
public int EpisodeCount { get; set; }
|
public int EpisodeCount { get; set; }
|
||||||
|
43
Jellyfin.Xtream/Client/NullStringDateTimeConverter.cs
Normal file
43
Jellyfin.Xtream/Client/NullStringDateTimeConverter.cs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
// Copyright (C) 2022 Kevin Jilissen
|
||||||
|
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Converters;
|
||||||
|
|
||||||
|
namespace Jellyfin.Xtream.Client;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Class NullStringConverter converts the literal string `null` to a null value.
|
||||||
|
/// </summary>
|
||||||
|
public class NullStringDateTimeConverter : IsoDateTimeConverter
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override bool CanConvert(Type objectType)
|
||||||
|
{
|
||||||
|
return objectType == typeof(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
if (reader.Value is string value && value.Equals("null", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return base.ReadJson(reader, objectType, existingValue, serializer);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user