Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 5 additions & 19 deletions src/RestApiClientSharp.Test.NUnit/UnitTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using AndreasReitberger.API.REST;
using AndreasReitberger.API.REST.Enums;
using AndreasReitberger.API.REST.Interfaces;
using AndreasReitberger.API.REST.SourceGeneration;
using AndreasReitberger.Shared.Core.Utilities;
using Newtonsoft.Json;
using RestApiClientSharp.Test.NUnit.Model;
using RestSharp;
Expand Down Expand Up @@ -42,32 +44,16 @@ public void Setup()
#endregion

#region JSON
[Test, Obsolete]
public void TestNewtonsoftJsonSerialization()
{
try
{
string? json = JsonConvert.SerializeObject(client, Formatting.Indented, settings: RestApiClient.DefaultNewtonsoftJsonSerializerSettings);
Assert.That(!string.IsNullOrEmpty(json));

RestApiClient? client2 = JsonConvert.DeserializeObject<RestApiClient>(json, settings: RestApiClient.DefaultNewtonsoftJsonSerializerSettings);
Assert.That(client2, Is.Not.Null);
}
catch (Exception ex)
{
Assert.Fail(ex.Message);
}
}

[Test]
public void TestJsonSerialization()
{
try
{
string? json = System.Text.Json.JsonSerializer.Serialize(client, options: RestApiClient.DefaultJsonSerializerSettings);
string? json = System.Text.Json.JsonSerializer.Serialize(client, typeof(RestApiClient), context: RestSourceGenerationContext.Default);
Assert.That(!string.IsNullOrEmpty(json));

RestApiClient? client2 = System.Text.Json.JsonSerializer.Deserialize<RestApiClient>(json, options: RestApiClient.DefaultJsonSerializerSettings);
RestApiClient? client2 = (RestApiClient?)System.Text.Json.JsonSerializer.Deserialize(json, typeof(RestApiClient), context: RestSourceGenerationContext.Default);
Assert.That(client2, Is.Not.Null);
}
catch (Exception ex)
Expand Down Expand Up @@ -101,7 +87,7 @@ public async Task TestQueryAsync()
.ConfigureAwait(false);
json = result?.Result;
Assert.That(!string.IsNullOrEmpty(json));
TestJson? resultObject = client.GetObjectFromJsonSystem<TestJson>(json);
TestJson? resultObject = JsonConvertHelper.ToObject<TestJson>(json!, settings: RestSourceGenerationContext.Default);
Assert.That(resultObject, Is.Not.Null);
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public partial class JsonConvertEventArgs : EventArgs, IJsonConvertEventArgs
public string? OriginalString { get; set; }
public string? TargetType { get; set; }

[JsonIgnore, Newtonsoft.Json.JsonIgnore]
[JsonIgnore]
public Exception? Exception { get; set; }
#endregion

Expand Down
26 changes: 0 additions & 26 deletions src/RestApiClientSharp/Models/JSON/Newtonsoft/AbstractConverter.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace AndreasReitberger.API.REST.JSON.System
/// <typeparam name="TType"></typeparam>
/// <typeparam name="TImplementation"></typeparam>

public sealed class TypeMappingConverter<
public class TypeMappingConverter<
#if NET5_0_OR_GREATER
[DynamicallyAccessedMembers(
DynamicallyAccessedMemberTypes.PublicParameterlessConstructor |
Expand Down
2 changes: 1 addition & 1 deletion src/RestApiClientSharp/Models/RestApiRequestRespone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public partial class RestApiRequestRespone : ObservableObject, IRestApiRequestRe
public partial IRestEventArgs? EventArgs { get; set; }

[ObservableProperty]
[JsonIgnore, Newtonsoft.Json.JsonIgnore]
[JsonIgnore]
public partial Exception? Exception { get; set; }

[ObservableProperty]
Expand Down
16 changes: 9 additions & 7 deletions src/RestApiClientSharp/RestApiClient.Clients.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using AndreasReitberger.API.REST.Interfaces;
using AndreasReitberger.API.REST.Utilities;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Net;
using System.Net.Http;
Expand All @@ -21,16 +19,16 @@ public partial class RestApiClient : ObservableObject, IRestApiClient
#region Clients

[ObservableProperty]
[Newtonsoft.Json.JsonIgnore, System.Text.Json.Serialization.JsonIgnore, XmlIgnore]
[JsonIgnore, XmlIgnore]
public partial RestClient? RestClient { get; set; }

[ObservableProperty]
[Newtonsoft.Json.JsonIgnore, System.Text.Json.Serialization.JsonIgnore, XmlIgnore]
[JsonIgnore, XmlIgnore]
public partial HttpClient? HttpClient { get; set; }

#if !NETFRAMEWORK
[ObservableProperty]
[Newtonsoft.Json.JsonIgnore, System.Text.Json.Serialization.JsonIgnore, XmlIgnore]
[JsonIgnore, XmlIgnore]
public partial RateLimitedHandler? RateLimitedHandler { get; set; }

public static RateLimiter DefaultLimiter = new TokenBucketRateLimiter(new()
Expand All @@ -44,7 +42,7 @@ public partial class RestApiClient : ObservableObject, IRestApiClient
});

[ObservableProperty]
[Newtonsoft.Json.JsonIgnore, System.Text.Json.Serialization.JsonIgnore, XmlIgnore]
[JsonIgnore, XmlIgnore]
public partial RateLimiter? Limiter { get; set; }
partial void OnLimiterChanged(RateLimiter? value) => UpdateRestClientInstance();
#endif
Expand Down Expand Up @@ -97,7 +95,11 @@ public virtual void UpdateRestClientInstance()

RestClientOptions options = new(target)
{
#if DEBUG
ThrowOnAnyError = true,
#else
ThrowOnAnyError = false,
#endif
Timeout = TimeSpan.FromSeconds(DefaultTimeout),
CookieContainer = new CookieContainer(),
};
Expand Down Expand Up @@ -134,6 +136,6 @@ public virtual void UpdateRestClientInstance()
}
UpdatingClients = false;
}
#endregion
#endregion
}
}
8 changes: 5 additions & 3 deletions src/RestApiClientSharp/RestApiClient.JsonSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ public partial class RestApiClient : ObservableObject, IRestApiClient
{

[ObservableProperty]
[Newtonsoft.Json.JsonIgnore, JsonIgnore, XmlIgnore]
public partial JsonSerializerOptions JsonSerializerSettings { get; set; } = DefaultJsonSerializerSettings;
[JsonIgnore, XmlIgnore]
public partial JsonSerializerOptions JsonSerializerSettings { get; set; } = RestSourceGenerationContext.Default.Options;

#region SerializerSettings

[Obsolete("This property is deprecated. Use the `RestSourceGenerationContext` instead.")]
public static JsonSerializerOptions DefaultJsonSerializerSettings = new()
{
TypeInfoResolver = RestSourceGenerationContext.Default,
Expand All @@ -34,6 +34,7 @@ public partial class RestApiClient : ObservableObject, IRestApiClient
#region Methods

#nullable enable
[Obsolete("This method is deprecated. Use the `JsonConvertHelper.ToObject<T>` method from the `SharedNetCoreLibrary` instead.")]
public T? GetObjectFromJsonSystem<T>(string? json, JsonSerializerContext serializerContext)
{
try
Expand All @@ -53,6 +54,7 @@ public partial class RestApiClient : ObservableObject, IRestApiClient
return default;
}
}
[Obsolete("This method is deprecated. Use the `JsonConvertHelper.ToObject<T>` method from the `SharedNetCoreLibrary` instead.")]
public T? GetObjectFromJsonSystem<T>(string? json, JsonSerializerOptions? serializerSettings = null)
{
try
Expand Down
80 changes: 0 additions & 80 deletions src/RestApiClientSharp/RestApiClient.NewtonsoftJsonSerializer.cs

This file was deleted.

3 changes: 1 addition & 2 deletions src/RestApiClientSharp/RestApiClient.Proxy.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AndreasReitberger.API.REST.Interfaces;
using Newtonsoft.Json;
using System.Net;

namespace AndreasReitberger.API.REST
Expand Down Expand Up @@ -37,7 +36,7 @@ public partial class RestApiClient : ObservableObject, IRestApiClient
partial void OnProxyUserChanged(string value) => UpdateRestClientInstance();

[ObservableProperty]
[Newtonsoft.Json.JsonIgnore, System.Text.Json.Serialization.JsonIgnore, XmlIgnore]
[JsonIgnore, XmlIgnore]
public partial string? ProxyPassword { get; set; }
partial void OnProxyPasswordChanged(string? value) => UpdateRestClientInstance();

Expand Down
2 changes: 1 addition & 1 deletion src/RestApiClientSharp/RestApiClient.Rest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected virtual bool GetQueryResult(string? result, bool emptyResultIsValid =
{
if ((string.IsNullOrEmpty(result) || result == "{}") && emptyResultIsValid)
return true;
return GetObjectFromJsonSystem<QueryActionResult>(result)?.Ok ?? false;
return JsonConvertHelper.ToObject<QueryActionResult>(result!, settings: RestSourceGenerationContext.Default)?.Ok ?? false;
}
catch (Exception exc)
{
Expand Down
16 changes: 8 additions & 8 deletions src/RestApiClientSharp/RestApiClient.WebSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ public partial class RestApiClient : ObservableObject, IRestApiClient

#region Properties
[ObservableProperty]
[Newtonsoft.Json.JsonIgnore, System.Text.Json.Serialization.JsonIgnore, XmlIgnore]
[JsonIgnore, XmlIgnore]
public partial WebsocketClient? WebSocket { get; set; }

[ObservableProperty]
[Newtonsoft.Json.JsonIgnore, System.Text.Json.Serialization.JsonIgnore, XmlIgnore]
[JsonIgnore, XmlIgnore]
public partial CancellationTokenSource? CtsPinging { get; set; }

[ObservableProperty]
[Newtonsoft.Json.JsonIgnore, System.Text.Json.Serialization.JsonIgnore, XmlIgnore]
[JsonIgnore, XmlIgnore]
public partial bool IsListening { get; set; } = false;
partial void OnIsListeningChanged(bool value)
{
Expand All @@ -43,7 +43,7 @@ partial void OnIsListeningChanged(bool value)
}

[ObservableProperty]
[Newtonsoft.Json.JsonIgnore, System.Text.Json.Serialization.JsonIgnore, XmlIgnore]
[JsonIgnore, XmlIgnore]
public partial Func<Task>? OnRefresh { get; set; }

[ObservableProperty]
Expand All @@ -57,7 +57,7 @@ partial void OnRefreshIntervalChanged(int value)
}

[ObservableProperty]
[Newtonsoft.Json.JsonIgnore, System.Text.Json.Serialization.JsonIgnore, XmlIgnore]
[JsonIgnore, XmlIgnore]
public partial long LastPingTimestamp { get; set; }

[ObservableProperty]
Expand All @@ -74,15 +74,15 @@ partial void OnPingIntervalChanged(int value)
}

[ObservableProperty]
[Newtonsoft.Json.JsonIgnore, System.Text.Json.Serialization.JsonIgnore, XmlIgnore]
[JsonIgnore, XmlIgnore]
public partial long PingCounter { get; set; } = 0;

[ObservableProperty]
[Newtonsoft.Json.JsonIgnore, System.Text.Json.Serialization.JsonIgnore, XmlIgnore]
[JsonIgnore, XmlIgnore]
public partial long LastRefreshTimestamp { get; set; }

[ObservableProperty]
[Newtonsoft.Json.JsonIgnore, System.Text.Json.Serialization.JsonIgnore, XmlIgnore]
[JsonIgnore, XmlIgnore]
public partial int RefreshCounter { get; set; } = 0;

[ObservableProperty]
Expand Down
6 changes: 3 additions & 3 deletions src/RestApiClientSharp/RestApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ public partial class RestApiClient : ObservableObject, IRestApiClient
public partial bool IsActive { get; set; } = false;

[ObservableProperty]
[Newtonsoft.Json.JsonIgnore, System.Text.Json.Serialization.JsonIgnore, XmlIgnore]
[JsonIgnore, XmlIgnore]
public partial bool IsConnecting { get; set; } = false;

[ObservableProperty]
[Newtonsoft.Json.JsonIgnore, System.Text.Json.Serialization.JsonIgnore, XmlIgnore]
[JsonIgnore, XmlIgnore]
public partial bool IsOnline { get; set; } = false;

[ObservableProperty]
[Newtonsoft.Json.JsonIgnore, System.Text.Json.Serialization.JsonIgnore, XmlIgnore]
[JsonIgnore, XmlIgnore]
public partial bool IsAccessTokenValid { get; set; } = false;

[ObservableProperty]
Expand Down
1 change: 0 additions & 1 deletion src/RestApiClientSharp/RestApiClientSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="RestSharp" Version="114.0.0" />
<PackageReference Include="SharedNetCoreLibrary" Version="1.2.8" />
<PackageReference Include="System.Text.Json" Version="10.0.8" />
Expand Down
1 change: 0 additions & 1 deletion src/RestApiClientSharp/RestApiConnectionBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AndreasReitberger.API.REST.Interfaces;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Threading.RateLimiting;

Expand Down
Loading
Loading