Error Newtonsoft.Json.JsonSerializationException: Error converting value #181

Open
opened 2025-05-18 16:20:34 +00:00 by tallw · 1 comment
tallw commented 2025-05-18 16:20:34 +00:00 (Migrated from github.com)
May 18 13:09:02 jellyfin jellyfin[27089]: [13:09:02] [ERR] Failed to get channel items
May 18 13:09:02 jellyfin jellyfin[27089]: Newtonsoft.Json.JsonSerializationException: Error converting value "https://www.themoviedb.org/t/p/original/yNNFFAVtfrMO8nGhi1AIuMDrw4b.jpg" to type 'System.Collections.Generic.ICollection1[System.String]'. Path '[0].backdrop_path', line 1, position 1853.
May 18 13:09:02 jellyfin jellyfin[27089]:  ---> System.ArgumentException: Could not cast or convert from System.String to System.Collections.Generic.ICollection1[System.String].
May 18 13:09:02 jellyfin jellyfin[27089]:    at Newtonsoft.Json.Utilities.ConvertUtils.EnsureTypeAssignable(Object value, Type initialType, Type targetType)
May 18 13:09:02 jellyfin jellyfin[27089]:    at Newtonsoft.Json.Utilities.ConvertUtils.ConvertOrCast(Object initialValue, CultureInfo culture, Type targetType)
May 18 13:09:02 jellyfin jellyfin[27089]:    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
May 18 13:09:02 jellyfin jellyfin[27089]:    --- End of inner exception stack trace ---
May 18 13:09:02 jellyfin jellyfin[27089]:    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
May 18 13:09:02 jellyfin jellyfin[27089]:    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
May 18 13:09:02 jellyfin jellyfin[27089]:    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
May 18 13:09:02 jellyfin jellyfin[27089]:    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
May 18 13:09:02 jellyfin jellyfin[27089]:    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
May 18 13:09:02 jellyfin jellyfin[27089]:    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
May 18 13:09:02 jellyfin jellyfin[27089]:    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
May 18 13:09:02 jellyfin jellyfin[27089]:    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
May 18 13:09:02 jellyfin jellyfin[27089]:    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
May 18 13:09:02 jellyfin jellyfin[27089]:    at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
May 18 13:09:02 jellyfin jellyfin[27089]:    at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
May 18 13:09:02 jellyfin jellyfin[27089]:    at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
May 18 13:09:02 jellyfin jellyfin[27089]:    at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value)
May 18 13:09:02 jellyfin jellyfin[27089]:    at Jellyfin.Xtream.Client.XtreamClient.QueryApi[T](ConnectionInfo connectionInfo, String urlPath, CancellationToken cancellationToken)
May 18 13:09:02 jellyfin jellyfin[27089]:    at Jellyfin.Xtream.Service.StreamService.GetSeries(Int32 categoryId, CancellationToken cancellationToken)
May 18 13:09:02 jellyfin jellyfin[27089]:    at Jellyfin.Xtream.SeriesChannel.GetSeries(Int32 categoryId, CancellationToken cancellationToken)
May 18 13:09:02 jellyfin jellyfin[27089]:    at Jellyfin.Xtream.SeriesChannel.GetChannelItems(InternalChannelItemQuery query, CancellationToken cancellationToken)
May 18 13:09:09 jellyfin jellyfin[27089]: [13:09:09] [INF] FFmpeg exited with code 0
O 

This error was detected when the series part was loaded.

```May 18 13:09:02 jellyfin systemd-journald[367]: [🡕] Suppressed 9817 messages from jellyfin.service May 18 13:09:02 jellyfin jellyfin[27089]: [13:09:02] [ERR] Failed to get channel items May 18 13:09:02 jellyfin jellyfin[27089]: Newtonsoft.Json.JsonSerializationException: Error converting value "https://www.themoviedb.org/t/p/original/yNNFFAVtfrMO8nGhi1AIuMDrw4b.jpg" to type 'System.Collections.Generic.ICollection1[System.String]'. Path '[0].backdrop_path', line 1, position 1853. May 18 13:09:02 jellyfin jellyfin[27089]: ---> System.ArgumentException: Could not cast or convert from System.String to System.Collections.Generic.ICollection1[System.String]. May 18 13:09:02 jellyfin jellyfin[27089]: at Newtonsoft.Json.Utilities.ConvertUtils.EnsureTypeAssignable(Object value, Type initialType, Type targetType) May 18 13:09:02 jellyfin jellyfin[27089]: at Newtonsoft.Json.Utilities.ConvertUtils.ConvertOrCast(Object initialValue, CultureInfo culture, Type targetType) May 18 13:09:02 jellyfin jellyfin[27089]: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType) May 18 13:09:02 jellyfin jellyfin[27089]: --- End of inner exception stack trace --- May 18 13:09:02 jellyfin jellyfin[27089]: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType) May 18 13:09:02 jellyfin jellyfin[27089]: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) May 18 13:09:02 jellyfin jellyfin[27089]: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id) May 18 13:09:02 jellyfin jellyfin[27089]: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) May 18 13:09:02 jellyfin jellyfin[27089]: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) May 18 13:09:02 jellyfin jellyfin[27089]: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id) May 18 13:09:02 jellyfin jellyfin[27089]: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id) May 18 13:09:02 jellyfin jellyfin[27089]: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) May 18 13:09:02 jellyfin jellyfin[27089]: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) May 18 13:09:02 jellyfin jellyfin[27089]: at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) May 18 13:09:02 jellyfin jellyfin[27089]: at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) May 18 13:09:02 jellyfin jellyfin[27089]: at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings) May 18 13:09:02 jellyfin jellyfin[27089]: at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value) May 18 13:09:02 jellyfin jellyfin[27089]: at Jellyfin.Xtream.Client.XtreamClient.QueryApi[T](ConnectionInfo connectionInfo, String urlPath, CancellationToken cancellationToken) May 18 13:09:02 jellyfin jellyfin[27089]: at Jellyfin.Xtream.Service.StreamService.GetSeries(Int32 categoryId, CancellationToken cancellationToken) May 18 13:09:02 jellyfin jellyfin[27089]: at Jellyfin.Xtream.SeriesChannel.GetSeries(Int32 categoryId, CancellationToken cancellationToken) May 18 13:09:02 jellyfin jellyfin[27089]: at Jellyfin.Xtream.SeriesChannel.GetChannelItems(InternalChannelItemQuery query, CancellationToken cancellationToken) May 18 13:09:09 jellyfin jellyfin[27089]: [13:09:09] [INF] FFmpeg exited with code 0 O ``` This error was detected when the series part was loaded.
tallw commented 2025-05-21 08:27:45 +00:00 (Migrated from github.com)

I ended up solving it, not sure if temporarily, by creating a class called "BackdropPathConverter"

using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Jellyfin.Xtream.Utils.Converters
{
    /// <summary>
    /// Converts between single string and string array for backdrop_path property.
    /// </summary>
    public sealed class BackdropPathConverter : JsonConverter<ICollection<string>?>
    {
        /// <inheritdoc />
        public override bool CanWrite => true;

        /// <inheritdoc />
        public override ICollection<string>? ReadJson(
            JsonReader reader,
            Type objectType,
            ICollection<string>? existingValue,
            bool hasExistingValue,
            JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.Null)
            {
                return null;
            }

            if (reader.TokenType == JsonToken.String)
            {
                string? singleValue = reader.Value?.ToString();
                return singleValue == null ? null : new List<string> { singleValue };
            }

            if (reader.TokenType == JsonToken.StartArray)
            {
                var array = JArray.Load(reader);
                return array.ToObject<List<string>>();
            }

            throw new JsonSerializationException($"Unexpected token type {reader.TokenType} when parsing backdrop_path");
        }

        /// <inheritdoc />
        public override void WriteJson(
            JsonWriter writer,
            ICollection<string>? value,
            JsonSerializer serializer)
        {
            if (value == null)
            {
                writer.WriteNull();
                return;
            }

            serializer.Serialize(writer, value);
        }
    }
}

And calling it in Series.cs
[JsonConverter(typeof(BackdropPathConverter))]

I ended up solving it, not sure if temporarily, by creating a class called "BackdropPathConverter" ``` using System; using System.Collections.Generic; using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace Jellyfin.Xtream.Utils.Converters { /// <summary> /// Converts between single string and string array for backdrop_path property. /// </summary> public sealed class BackdropPathConverter : JsonConverter<ICollection<string>?> { /// <inheritdoc /> public override bool CanWrite => true; /// <inheritdoc /> public override ICollection<string>? ReadJson( JsonReader reader, Type objectType, ICollection<string>? existingValue, bool hasExistingValue, JsonSerializer serializer) { if (reader.TokenType == JsonToken.Null) { return null; } if (reader.TokenType == JsonToken.String) { string? singleValue = reader.Value?.ToString(); return singleValue == null ? null : new List<string> { singleValue }; } if (reader.TokenType == JsonToken.StartArray) { var array = JArray.Load(reader); return array.ToObject<List<string>>(); } throw new JsonSerializationException($"Unexpected token type {reader.TokenType} when parsing backdrop_path"); } /// <inheritdoc /> public override void WriteJson( JsonWriter writer, ICollection<string>? value, JsonSerializer serializer) { if (value == null) { writer.WriteNull(); return; } serializer.Serialize(writer, value); } } } ``` And calling it in Series.cs [JsonConverter(typeof(BackdropPathConverter))]
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Sirherobrine23/Jellyfin_Xtream#181
No description provided.