diff --git a/Consul/Client.cs b/Consul/Client.cs
index 89fa487d..8d312215 100644
--- a/Consul/Client.cs
+++ b/Consul/Client.cs
@@ -23,6 +23,7 @@
using System.Net.Http.Headers;
using System.Security.Cryptography.X509Certificates;
using Consul.Filtering;
+using Newtonsoft.Json;
namespace Consul
{
@@ -62,6 +63,11 @@ internal bool DisableServerCertificateValidation
}
}
+ ///
+ /// Allows to configure the serialization settings for a Consul client.
+ ///
+ public Action ConfigureSerializerSettings { get; set; }
+
///
/// The Uri to connect to the Consul agent.
///
diff --git a/Consul/Client_Request.cs b/Consul/Client_Request.cs
index b2f41a2c..cb70cb05 100644
--- a/Consul/Client_Request.cs
+++ b/Consul/Client_Request.cs
@@ -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)
{
@@ -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);