diff --git a/back/src/Kyoo.Abstractions/Kyoo.Abstractions.csproj b/back/src/Kyoo.Abstractions/Kyoo.Abstractions.csproj index 2861264a..9613d37c 100644 --- a/back/src/Kyoo.Abstractions/Kyoo.Abstractions.csproj +++ b/back/src/Kyoo.Abstractions/Kyoo.Abstractions.csproj @@ -10,11 +10,9 @@ - - diff --git a/back/src/Kyoo.Abstractions/Models/Attributes/Serializer/DeserializeIgnoreAttribute.cs b/back/src/Kyoo.Abstractions/Models/Attributes/Serializer/DeserializeIgnoreAttribute.cs deleted file mode 100644 index 8b10ee87..00000000 --- a/back/src/Kyoo.Abstractions/Models/Attributes/Serializer/DeserializeIgnoreAttribute.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Kyoo - A portable and vast media library solution. -// Copyright (c) Kyoo. -// -// See AUTHORS.md and LICENSE file in the project root for full license information. -// -// Kyoo 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 -// any later version. -// -// Kyoo 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 Kyoo. If not, see . - -using System; - -namespace Kyoo.Abstractions.Models.Attributes -{ - /// - /// Remove a property from the deserialization pipeline. The user can't input value for this property. - /// - [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] - public class DeserializeIgnoreAttribute : Attribute { } -} diff --git a/back/src/Kyoo.Abstractions/Models/Attributes/Serializer/SerializeIgnoreAttribute.cs b/back/src/Kyoo.Abstractions/Models/Attributes/Serializer/SerializeIgnoreAttribute.cs deleted file mode 100644 index 4a87d3f9..00000000 --- a/back/src/Kyoo.Abstractions/Models/Attributes/Serializer/SerializeIgnoreAttribute.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Kyoo - A portable and vast media library solution. -// Copyright (c) Kyoo. -// -// See AUTHORS.md and LICENSE file in the project root for full license information. -// -// Kyoo 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 -// any later version. -// -// Kyoo 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 Kyoo. If not, see . - -using System; - -namespace Kyoo.Abstractions.Models.Attributes -{ - /// - /// Remove an property from the serialization pipeline. It will simply be skipped. - /// - [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] - public class SerializeIgnoreAttribute : Attribute { } -} diff --git a/back/src/Kyoo.Abstractions/Models/Resources/Collection.cs b/back/src/Kyoo.Abstractions/Models/Resources/Collection.cs index 75f8b5d9..23dd12ba 100644 --- a/back/src/Kyoo.Abstractions/Models/Resources/Collection.cs +++ b/back/src/Kyoo.Abstractions/Models/Resources/Collection.cs @@ -19,10 +19,9 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.Text.Json.Serialization; using Kyoo.Abstractions.Controllers; -using Kyoo.Abstractions.Models.Attributes; using Kyoo.Utils; -using Newtonsoft.Json; namespace Kyoo.Abstractions.Models { @@ -65,13 +64,13 @@ namespace Kyoo.Abstractions.Models /// /// The list of movies contained in this collection. /// - [SerializeIgnore] + [JsonIgnore] public ICollection? Movies { get; set; } /// /// The list of shows contained in this collection. /// - [SerializeIgnore] + [JsonIgnore] public ICollection? Shows { get; set; } /// diff --git a/back/src/Kyoo.Abstractions/Models/Resources/Episode.cs b/back/src/Kyoo.Abstractions/Models/Resources/Episode.cs index 09a33b2d..d8325426 100644 --- a/back/src/Kyoo.Abstractions/Models/Resources/Episode.cs +++ b/back/src/Kyoo.Abstractions/Models/Resources/Episode.cs @@ -20,9 +20,9 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Text.Json.Serialization; using System.Text.RegularExpressions; using EntityFrameworkCore.Projectables; -using JetBrains.Annotations; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models.Attributes; @@ -60,7 +60,6 @@ namespace Kyoo.Abstractions.Models ); return GetSlug(ShowId.ToString(), SeasonNumber, EpisodeNumber, AbsoluteNumber); } - [UsedImplicitly] private set { Match match = Regex.Match(value, @"(?.+)-s(?\d+)e(?\d+)"); @@ -90,7 +89,7 @@ namespace Kyoo.Abstractions.Models /// /// The slug of the Show that contain this episode. If this is not set, this episode is ill-formed. /// - [SerializeIgnore] + [JsonIgnore] public string? ShowSlug { private get; set; } /// @@ -249,7 +248,7 @@ namespace Kyoo.Abstractions.Models || (x.SeasonNumber == SeasonNumber && x.EpisodeNumber > EpisodeNumber) ); - [SerializeIgnore] + [JsonIgnore] public ICollection? Watched { get; set; } /// diff --git a/back/src/Kyoo.Abstractions/Models/Resources/Movie.cs b/back/src/Kyoo.Abstractions/Models/Resources/Movie.cs index bdab427e..092432ce 100644 --- a/back/src/Kyoo.Abstractions/Models/Resources/Movie.cs +++ b/back/src/Kyoo.Abstractions/Models/Resources/Movie.cs @@ -21,11 +21,11 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; +using System.Text.Json.Serialization; using EntityFrameworkCore.Projectables; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models.Attributes; using Kyoo.Utils; -using Newtonsoft.Json; namespace Kyoo.Abstractions.Models { @@ -119,11 +119,11 @@ namespace Kyoo.Abstractions.Models /// public Image? Logo { get; set; } - [SerializeIgnore] + [JsonIgnore] [Column("air_date")] public DateTime? StartAir => AirDate; - [SerializeIgnore] + [JsonIgnore] [Column("air_date")] public DateTime? EndAir => AirDate; @@ -138,7 +138,7 @@ namespace Kyoo.Abstractions.Models /// /// The ID of the Studio that made this show. /// - [SerializeIgnore] + [JsonIgnore] public Guid? StudioId { get; set; } /// @@ -155,7 +155,7 @@ namespace Kyoo.Abstractions.Models /// /// The list of collections that contains this show. /// - [SerializeIgnore] + [JsonIgnore] public ICollection? Collections { get; set; } /// @@ -164,7 +164,7 @@ namespace Kyoo.Abstractions.Models public VideoLinks Links => new() { Direct = $"/movie/{Slug}/direct", Hls = $"/movie/{Slug}/master.m3u8", }; - [SerializeIgnore] + [JsonIgnore] public ICollection? Watched { get; set; } /// diff --git a/back/src/Kyoo.Abstractions/Models/Resources/People.cs b/back/src/Kyoo.Abstractions/Models/Resources/People.cs index 336b7e6b..7537440d 100644 --- a/back/src/Kyoo.Abstractions/Models/Resources/People.cs +++ b/back/src/Kyoo.Abstractions/Models/Resources/People.cs @@ -20,10 +20,9 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Text.Json.Serialization; using Kyoo.Abstractions.Controllers; -using Kyoo.Abstractions.Models.Attributes; using Kyoo.Utils; -using Newtonsoft.Json; namespace Kyoo.Abstractions.Models { @@ -62,7 +61,7 @@ namespace Kyoo.Abstractions.Models /// /// The list of roles this person has played in. See for more information. /// - [SerializeIgnore] + [JsonIgnore] public ICollection? Roles { get; set; } public People() { } diff --git a/back/src/Kyoo.Abstractions/Models/Resources/Season.cs b/back/src/Kyoo.Abstractions/Models/Resources/Season.cs index df0ae10d..64c3cfe2 100644 --- a/back/src/Kyoo.Abstractions/Models/Resources/Season.cs +++ b/back/src/Kyoo.Abstractions/Models/Resources/Season.cs @@ -20,9 +20,9 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Text.Json.Serialization; using System.Text.RegularExpressions; using EntityFrameworkCore.Projectables; -using JetBrains.Annotations; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models.Attributes; @@ -49,8 +49,6 @@ namespace Kyoo.Abstractions.Models return $"{ShowId}-s{SeasonNumber}"; return $"{ShowSlug ?? Show?.Slug}-s{SeasonNumber}"; } - [UsedImplicitly] - [NotNull] private set { Match match = Regex.Match(value, @"(?.+)-s(?\d+)"); @@ -67,7 +65,7 @@ namespace Kyoo.Abstractions.Models /// /// The slug of the Show that contain this episode. If this is not set, this season is ill-formed. /// - [SerializeIgnore] + [JsonIgnore] public string? ShowSlug { private get; set; } /// @@ -124,7 +122,7 @@ namespace Kyoo.Abstractions.Models /// /// The list of episodes that this season contains. /// - [SerializeIgnore] + [JsonIgnore] public ICollection? Episodes { get; set; } /// diff --git a/back/src/Kyoo.Abstractions/Models/Resources/Show.cs b/back/src/Kyoo.Abstractions/Models/Resources/Show.cs index 6da2fe34..c0ddc4f6 100644 --- a/back/src/Kyoo.Abstractions/Models/Resources/Show.cs +++ b/back/src/Kyoo.Abstractions/Models/Resources/Show.cs @@ -21,11 +21,11 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; +using System.Text.Json.Serialization; using EntityFrameworkCore.Projectables; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models.Attributes; using Kyoo.Utils; -using Newtonsoft.Json; namespace Kyoo.Abstractions.Models { @@ -119,7 +119,7 @@ namespace Kyoo.Abstractions.Models /// public string? Trailer { get; set; } - [SerializeIgnore] + [JsonIgnore] [Column("start_air")] public DateTime? AirDate => StartAir; @@ -129,7 +129,7 @@ namespace Kyoo.Abstractions.Models /// /// The ID of the Studio that made this show. /// - [SerializeIgnore] + [JsonIgnore] public Guid? StudioId { get; set; } /// @@ -146,7 +146,7 @@ namespace Kyoo.Abstractions.Models /// /// The different seasons in this show. If this is a movie, this list is always null or empty. /// - [SerializeIgnore] + [JsonIgnore] public ICollection? Seasons { get; set; } /// @@ -154,13 +154,13 @@ namespace Kyoo.Abstractions.Models /// If this is a movie, there will be a unique episode (with the seasonNumber and episodeNumber set to null). /// Having an episode is necessary to store metadata and tracks. /// - [SerializeIgnore] + [JsonIgnore] public ICollection? Episodes { get; set; } /// /// The list of collections that contains this show. /// - [SerializeIgnore] + [JsonIgnore] public ICollection? Collections { get; set; } /// @@ -213,7 +213,7 @@ namespace Kyoo.Abstractions.Models private int _EpisodesCount => Episodes!.Count; - [SerializeIgnore] + [JsonIgnore] public ICollection? Watched { get; set; } /// diff --git a/back/src/Kyoo.Abstractions/Models/Resources/Studio.cs b/back/src/Kyoo.Abstractions/Models/Resources/Studio.cs index 2f4eef3d..4f9f69f2 100644 --- a/back/src/Kyoo.Abstractions/Models/Resources/Studio.cs +++ b/back/src/Kyoo.Abstractions/Models/Resources/Studio.cs @@ -19,10 +19,9 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.Text.Json.Serialization; using Kyoo.Abstractions.Controllers; -using Kyoo.Abstractions.Models.Attributes; using Kyoo.Utils; -using Newtonsoft.Json; namespace Kyoo.Abstractions.Models { @@ -48,13 +47,13 @@ namespace Kyoo.Abstractions.Models /// /// The list of shows that are made by this studio. /// - [SerializeIgnore] + [JsonIgnore] public ICollection? Shows { get; set; } /// /// The list of movies that are made by this studio. /// - [SerializeIgnore] + [JsonIgnore] public ICollection? Movies { get; set; } /// diff --git a/back/src/Kyoo.Abstractions/Models/Resources/User.cs b/back/src/Kyoo.Abstractions/Models/Resources/User.cs index 6afeccb8..027d086d 100644 --- a/back/src/Kyoo.Abstractions/Models/Resources/User.cs +++ b/back/src/Kyoo.Abstractions/Models/Resources/User.cs @@ -19,10 +19,9 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.Text.Json.Serialization; using Kyoo.Abstractions.Controllers; -using Kyoo.Abstractions.Models.Attributes; using Kyoo.Utils; -using Newtonsoft.Json; namespace Kyoo.Abstractions.Models { @@ -53,7 +52,7 @@ namespace Kyoo.Abstractions.Models /// /// The user password (hashed, it can't be read like that). The hashing format is implementation defined. /// - [SerializeIgnore] + [JsonIgnore] public string? Password { get; set; } /// diff --git a/back/src/Kyoo.Abstractions/Models/Resources/WatchStatus.cs b/back/src/Kyoo.Abstractions/Models/Resources/WatchStatus.cs index bc67f0bd..53543b32 100644 --- a/back/src/Kyoo.Abstractions/Models/Resources/WatchStatus.cs +++ b/back/src/Kyoo.Abstractions/Models/Resources/WatchStatus.cs @@ -17,6 +17,7 @@ // along with Kyoo. If not, see . using System; +using System.Text.Json.Serialization; using Kyoo.Abstractions.Models.Attributes; namespace Kyoo.Abstractions.Models @@ -62,7 +63,7 @@ namespace Kyoo.Abstractions.Models /// /// The user that started watching this episode. /// - [SerializeIgnore] + [JsonIgnore] public User User { get; set; } /// @@ -74,7 +75,7 @@ namespace Kyoo.Abstractions.Models /// /// The started. /// - [SerializeIgnore] + [JsonIgnore] public Movie Movie { get; set; } /// @@ -119,7 +120,7 @@ namespace Kyoo.Abstractions.Models /// /// The user that started watching this episode. /// - [SerializeIgnore] + [JsonIgnore] public User User { get; set; } /// @@ -131,7 +132,7 @@ namespace Kyoo.Abstractions.Models /// /// The started. /// - [SerializeIgnore] + [JsonIgnore] public Episode Episode { get; set; } /// @@ -176,7 +177,7 @@ namespace Kyoo.Abstractions.Models /// /// The user that started watching this episode. /// - [SerializeIgnore] + [JsonIgnore] public User User { get; set; } /// @@ -188,7 +189,7 @@ namespace Kyoo.Abstractions.Models /// /// The started. /// - [SerializeIgnore] + [JsonIgnore] public Show Show { get; set; } /// diff --git a/back/src/Kyoo.Core/Views/Helper/Serializers/JsonOptions.cs b/back/src/Kyoo.Core/Views/Helper/Serializers/JsonOptions.cs index 5da2d274..f44796d5 100644 --- a/back/src/Kyoo.Core/Views/Helper/Serializers/JsonOptions.cs +++ b/back/src/Kyoo.Core/Views/Helper/Serializers/JsonOptions.cs @@ -50,7 +50,6 @@ namespace Kyoo.Core.Api options.SerializerSettings.ContractResolver = new JsonSerializerContract( _httpContextAccessor ); - options.SerializerSettings.Converters.Add(new PeopleRoleConverter()); } } } diff --git a/back/src/Kyoo.Core/Views/Helper/Serializers/JsonSerializerContract.cs b/back/src/Kyoo.Core/Views/Helper/Serializers/JsonSerializerContract.cs index 10248071..cfba3390 100644 --- a/back/src/Kyoo.Core/Views/Helper/Serializers/JsonSerializerContract.cs +++ b/back/src/Kyoo.Core/Views/Helper/Serializers/JsonSerializerContract.cs @@ -73,11 +73,6 @@ namespace Kyoo.Core.Api return fields.Contains(member.Name); }; } - - if (member.GetCustomAttribute() != null) - property.ShouldSerialize = _ => false; - if (member.GetCustomAttribute() != null) - property.ShouldDeserialize = _ => false; return property; } @@ -111,16 +106,9 @@ namespace Kyoo.Core.Api return properties; } - public class FixedValueProvider : IValueProvider + public class FixedValueProvider(object value) : IValueProvider { - private readonly object _value; - - public FixedValueProvider(object value) - { - _value = value; - } - - public object GetValue(object target) => _value; + public object GetValue(object target) => value; public void SetValue(object target, object? value) => throw new NotImplementedException(); diff --git a/back/src/Kyoo.Core/Views/Helper/Serializers/PeopleRoleConverter.cs b/back/src/Kyoo.Core/Views/Helper/Serializers/PeopleRoleConverter.cs deleted file mode 100644 index 773a8d9b..00000000 --- a/back/src/Kyoo.Core/Views/Helper/Serializers/PeopleRoleConverter.cs +++ /dev/null @@ -1,76 +0,0 @@ -// Kyoo - A portable and vast media library solution. -// Copyright (c) Kyoo. -// -// See AUTHORS.md and LICENSE file in the project root for full license information. -// -// Kyoo 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 -// any later version. -// -// Kyoo 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 Kyoo. If not, see . - -using System; -using System.Collections.Generic; -using Kyoo.Abstractions.Models; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - -namespace Kyoo.Core.Api -{ - /// - /// A custom role's convertor to inline the person or the show depending on the value of - /// . - /// - public class PeopleRoleConverter : JsonConverter - { - /// - public override void WriteJson( - JsonWriter writer, - PeopleRole? value, - JsonSerializer serializer - ) - { - // if (value == null) - // { - // writer.WriteNull(); - // return; - // } - // - // ICollection? oldPeople = value.Show?.People; - // ICollection? oldRoles = value.People?.Roles; - // if (value.Show != null) - // value.Show.People = null; - // if (value.People != null) - // value.People.Roles = null; - // - // JObject obj = JObject.FromObject((value.ForPeople ? value.People : value.Show)!, serializer); - // obj.Add("role", value.Role); - // obj.Add("type", value.Type); - // obj.WriteTo(writer); - // - // if (value.Show != null) - // value.Show.People = oldPeople; - // if (value.People != null) - // value.People.Roles = oldRoles; - } - - /// - public override PeopleRole ReadJson( - JsonReader reader, - Type objectType, - PeopleRole? existingValue, - bool hasExistingValue, - JsonSerializer serializer - ) - { - throw new NotImplementedException(); - } - } -}