Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 0 additions & 17 deletions Activout.RestClient.Newtonsoft.Json/JsonHelper.cs

This file was deleted.

20 changes: 20 additions & 0 deletions Activout.RestClient.Newtonsoft.Json/NewtonsoftJsonDefaults.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json;

namespace Activout.RestClient.Newtonsoft.Json;

[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public static class NewtonsoftJsonDefaults
{
public static readonly MediaType[] SupportedMediaTypes =
[
MediaType.ValueOf("application/json")
];

public static readonly JsonConverter[] DefaultJsonConverters = [new SimpleValueObjectConverter()];

public static readonly JsonSerializerSettings DefaultJsonSerializerSettings = new()
{
Converters = DefaultJsonConverters.ToList()
};
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Activout.RestClient.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
Expand All @@ -13,7 +8,7 @@ public class NewtonsoftJsonDeserializer : IDeserializer
{
private readonly JsonSerializerSettings _jsonSerializerSettings;

public IReadOnlyCollection<MediaType> SupportedMediaTypes => JsonHelper.SupportedMediaTypes;
public IReadOnlyCollection<MediaType> SupportedMediaTypes => NewtonsoftJsonDefaults.SupportedMediaTypes;

public NewtonsoftJsonDeserializer(JsonSerializerSettings jsonSerializerSettings)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using Activout.RestClient.Serialization;
using Newtonsoft.Json;
Expand All @@ -11,7 +8,7 @@ public class NewtonsoftJsonSerializer : ISerializer
{
private readonly JsonSerializerSettings _jsonSerializerSettings;

public IReadOnlyCollection<MediaType> SupportedMediaTypes => JsonHelper.SupportedMediaTypes;
public IReadOnlyCollection<MediaType> SupportedMediaTypes => NewtonsoftJsonDefaults.SupportedMediaTypes;

public NewtonsoftJsonSerializer(JsonSerializerSettings jsonSerializerSettings)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,18 @@
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;

namespace Activout.RestClient.Newtonsoft.Json
namespace Activout.RestClient.Newtonsoft.Json;

public static class RestClientBuilderNewtonsoftJsonExtensions
{
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public static class RestClientBuilderNewtonsoftJsonExtensions
public static IRestClientBuilder WithNewtonsoftJson(this IRestClientBuilder builder,
JsonSerializerSettings? jsonSerializerSettings = null)
{
public static readonly IReadOnlyCollection<JsonConverter> DefaultJsonConverters = new List<JsonConverter>
{ new SimpleValueObjectConverter() }.ToImmutableList();

public static readonly JsonSerializerSettings DefaultJsonSerializerSettings = new()
{
Converters = DefaultJsonConverters.ToList()
};

public static IRestClientBuilder WithNewtonsoftJson(this IRestClientBuilder builder,
JsonSerializerSettings? jsonSerializerSettings = null)
{
var settings = jsonSerializerSettings ?? DefaultJsonSerializerSettings;
var settings = jsonSerializerSettings ?? NewtonsoftJsonDefaults.DefaultJsonSerializerSettings;

builder.With(new NewtonsoftJsonSerializer(settings));
builder.With(new NewtonsoftJsonDeserializer(settings));
builder.With(new NewtonsoftJsonSerializer(settings));
builder.With(new NewtonsoftJsonDeserializer(settings));

return builder;
}
return builder;
}
}