From 5c864280719acda67bf7b707fe90d00d6b9ceb4b Mon Sep 17 00:00:00 2001 From: Ben Simpson Date: Tue, 20 Oct 2020 16:02:00 +1300 Subject: [PATCH] Fix serializer settings issue --- .../src/io/fusionauth/DefaultRESTClient.cs | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/fusionauth-netcore-client/src/io/fusionauth/DefaultRESTClient.cs b/fusionauth-netcore-client/src/io/fusionauth/DefaultRESTClient.cs index fd68be22..7c052038 100644 --- a/fusionauth-netcore-client/src/io/fusionauth/DefaultRESTClient.cs +++ b/fusionauth-netcore-client/src/io/fusionauth/DefaultRESTClient.cs @@ -40,18 +40,17 @@ class DefaultRESTClient : IRESTClient { public Dictionary headers = new Dictionary(); - static DefaultRESTClient() { - JsonConvert.DefaultSettings = () => - new JsonSerializerSettings { - NullValueHandling = NullValueHandling.Ignore, - Converters = new List { + private static readonly JsonSerializerSettings SerializerSettings = new JsonSerializerSettings + { + NullValueHandling = NullValueHandling.Ignore, + Converters = new List + { new StringEnumConverter(), new DateTimeOffsetConverter(), new IdentityProviderConverter() - }, - ContractResolver = new DefaultContractResolver() - }; - } + }, + ContractResolver = new DefaultContractResolver() + }; public DefaultRESTClient(string host) { httpClient = new HttpClient {BaseAddress = new Uri(host)}; @@ -112,7 +111,7 @@ public override IRESTClient withFormData(FormUrlEncodedContent body) * @param body The object to be written to the request body as JSON. */ public override IRESTClient withJSONBody(object body) { - content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, + content = new StringContent(JsonConvert.SerializeObject(body, SerializerSettings), Encoding.UTF8, "application/json"); return this; } @@ -205,11 +204,11 @@ public override Task> goAsync() { clientResponse.statusCode = (int)result.StatusCode; if (clientResponse.statusCode >= 300) { clientResponse.errorResponse = - JsonConvert.DeserializeObject(result.Content.ReadAsStringAsync().Result); + JsonConvert.DeserializeObject(result.Content.ReadAsStringAsync().Result, SerializerSettings); } else { clientResponse.successResponse = - JsonConvert.DeserializeObject(result.Content.ReadAsStringAsync().Result); + JsonConvert.DeserializeObject(result.Content.ReadAsStringAsync().Result, SerializerSettings); } } catch (Exception e)