diff --git a/back/src/Kyoo.Abstractions/Models/Patch.cs b/back/src/Kyoo.Abstractions/Models/Patch.cs index 305a76fb..1eafe949 100644 --- a/back/src/Kyoo.Abstractions/Models/Patch.cs +++ b/back/src/Kyoo.Abstractions/Models/Patch.cs @@ -19,27 +19,27 @@ using System; using System.Collections.Generic; using System.Reflection; +using System.Text.Json; using Kyoo.Abstractions.Models; -using Newtonsoft.Json.Linq; namespace Kyoo.Models; -public class Patch : Dictionary +public class Patch : Dictionary where T : class, IResource { - public Guid? Id => this.GetValueOrDefault(nameof(IResource.Id))?.ToObject(); + public Guid? Id => this.GetValueOrDefault(nameof(IResource.Id))?.Deserialize(); - public string? Slug => this.GetValueOrDefault(nameof(IResource.Slug))?.ToObject(); + public string? Slug => this.GetValueOrDefault(nameof(IResource.Slug))?.Deserialize(); public T Apply(T current) { - foreach ((string property, JToken value) in this) + foreach ((string property, JsonDocument value) in this) { PropertyInfo prop = typeof(T).GetProperty( property, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance )!; - prop.SetValue(current, value.ToObject(prop.PropertyType)); + prop.SetValue(current, value.Deserialize(prop.PropertyType)); } return current; } diff --git a/back/src/Kyoo.Abstractions/Models/Resources/Interfaces/IThumbnails.cs b/back/src/Kyoo.Abstractions/Models/Resources/Interfaces/IThumbnails.cs index b590c98d..aed090b1 100644 --- a/back/src/Kyoo.Abstractions/Models/Resources/Interfaces/IThumbnails.cs +++ b/back/src/Kyoo.Abstractions/Models/Resources/Interfaces/IThumbnails.cs @@ -20,8 +20,8 @@ using System; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Globalization; +using System.Text.Json.Serialization; using Kyoo.Abstractions.Models.Attributes; -using Newtonsoft.Json; namespace Kyoo.Abstractions.Models { diff --git a/back/src/Kyoo.Abstractions/Models/Resources/JwtToken.cs b/back/src/Kyoo.Abstractions/Models/Resources/JwtToken.cs index d2c8eacd..1342dc07 100644 --- a/back/src/Kyoo.Abstractions/Models/Resources/JwtToken.cs +++ b/back/src/Kyoo.Abstractions/Models/Resources/JwtToken.cs @@ -18,7 +18,6 @@ using System; using System.Text.Json.Serialization; -using Newtonsoft.Json; namespace Kyoo.Abstractions.Models; @@ -36,21 +35,18 @@ public class JwtToken(string accessToken, string refreshToken, TimeSpan expireIn /// /// The type of this token (always a Bearer). /// - [JsonProperty("token_type")] [JsonPropertyName("token_type")] public string TokenType => "Bearer"; /// /// The access token used to authorize requests. /// - [JsonProperty("access_token")] [JsonPropertyName("access_token")] public string AccessToken { get; set; } = accessToken; /// /// The refresh token used to retrieve a new access/refresh token when the access token has expired. /// - [JsonProperty("refresh_token")] [JsonPropertyName("refresh_token")] public string RefreshToken { get; set; } = refreshToken; @@ -58,14 +54,12 @@ public class JwtToken(string accessToken, string refreshToken, TimeSpan expireIn /// When the access token will expire. After this time, the refresh token should be used to retrieve. /// a new token.cs /// - [JsonProperty("expire_in")] [JsonPropertyName("expire_in")] public TimeSpan ExpireIn => ExpireAt.Subtract(DateTime.UtcNow); /// /// The exact date at which the access token will expire. /// - [JsonProperty("expire_at")] [JsonPropertyName("expire_at")] public DateTime ExpireAt { get; set; } = DateTime.UtcNow + expireIn; } diff --git a/back/src/Kyoo.Authentication/Kyoo.Authentication.csproj b/back/src/Kyoo.Authentication/Kyoo.Authentication.csproj index b273ee03..83a794b7 100644 --- a/back/src/Kyoo.Authentication/Kyoo.Authentication.csproj +++ b/back/src/Kyoo.Authentication/Kyoo.Authentication.csproj @@ -7,7 +7,6 @@ - diff --git a/back/src/Kyoo.Core/Kyoo.Core.csproj b/back/src/Kyoo.Core/Kyoo.Core.csproj index 783954ce..91fabccd 100644 --- a/back/src/Kyoo.Core/Kyoo.Core.csproj +++ b/back/src/Kyoo.Core/Kyoo.Core.csproj @@ -12,8 +12,6 @@ - - diff --git a/back/src/Kyoo.Postgresql/Utils/JsonTypeHandler.cs b/back/src/Kyoo.Postgresql/Utils/JsonTypeHandler.cs index 1eff28a2..e9655389 100644 --- a/back/src/Kyoo.Postgresql/Utils/JsonTypeHandler.cs +++ b/back/src/Kyoo.Postgresql/Utils/JsonTypeHandler.cs @@ -17,7 +17,7 @@ // along with Kyoo. If not, see . using System.Data; -using Newtonsoft.Json; +using System.Text.Json; using Npgsql; using NpgsqlTypes; using static Dapper.SqlMapper; @@ -30,13 +30,13 @@ public class JsonTypeHandler : TypeHandler public override T? Parse(object value) { if (value is string str) - return JsonConvert.DeserializeObject(str); + return JsonSerializer.Deserialize(str); return default; } public override void SetValue(IDbDataParameter parameter, T? value) { - parameter.Value = JsonConvert.SerializeObject(value); + parameter.Value = JsonSerializer.Serialize(value); ((NpgsqlParameter)parameter).NpgsqlDbType = NpgsqlDbType.Jsonb; } }