Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure JSON serializer #413

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions Consul/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using System.Net.Http.Headers;
using System.Security.Cryptography.X509Certificates;
using Consul.Filtering;
using Newtonsoft.Json;

namespace Consul
{
Expand Down Expand Up @@ -62,6 +63,11 @@ internal bool DisableServerCertificateValidation
}
}

/// <summary>
/// Allows to configure the serialization settings for a Consul client.
/// </summary>
public Action<JsonSerializerSettings> ConfigureSerializerSettings { get; set; }

/// <summary>
/// The Uri to connect to the Consul agent.
/// </summary>
Expand Down
13 changes: 12 additions & 1 deletion Consul/Client_Request.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public abstract class ConsulRequest
internal Stream ResponseStream { get; set; }
internal string Endpoint { get; set; }

internal readonly JsonSerializer _serializer = new JsonSerializer();
internal readonly JsonSerializer _serializer;

internal ConsulRequest(ConsulClient client, string url, HttpMethod method)
{
Expand All @@ -78,6 +78,17 @@ internal ConsulRequest(ConsulClient client, string url, HttpMethod method)
{
Params["ns"] = client.Config.Namespace;
}

if (client.Config.ConfigureSerializerSettings == null)
{
_serializer = new JsonSerializer();
}
else
{
var settings = new JsonSerializerSettings();
client.Config.ConfigureSerializerSettings(settings);
_serializer = JsonSerializer.Create(settings);
}
}

protected abstract void ApplyOptions(ConsulClientConfiguration clientConfig);
Expand Down
Loading