Skip to content

Commit

Permalink
Merge pull request #27 from EducationPerfect/master
Browse files Browse the repository at this point in the history
Don't overwrite default serializer settings (#21)
  • Loading branch information
robotdan authored Oct 21, 2020
2 parents ee33644 + 5c86428 commit f2d6487
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions fusionauth-netcore-client/src/io/fusionauth/DefaultRESTClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,17 @@ class DefaultRESTClient : IRESTClient {

public Dictionary<string, string> headers = new Dictionary<string, string>();

static DefaultRESTClient() {
JsonConvert.DefaultSettings = () =>
new JsonSerializerSettings {
NullValueHandling = NullValueHandling.Ignore,
Converters = new List<JsonConverter> {
private static readonly JsonSerializerSettings SerializerSettings = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
Converters = new List<JsonConverter>
{
new StringEnumConverter(),
new DateTimeOffsetConverter(),
new IdentityProviderConverter()
},
ContractResolver = new DefaultContractResolver()
};
}
},
ContractResolver = new DefaultContractResolver()
};

public DefaultRESTClient(string host) {
httpClient = new HttpClient {BaseAddress = new Uri(host)};
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -205,11 +204,11 @@ public override Task<ClientResponse<T>> goAsync<T>() {
clientResponse.statusCode = (int)result.StatusCode;
if (clientResponse.statusCode >= 300) {
clientResponse.errorResponse =
JsonConvert.DeserializeObject<Errors>(result.Content.ReadAsStringAsync().Result);
JsonConvert.DeserializeObject<Errors>(result.Content.ReadAsStringAsync().Result, SerializerSettings);
}
else {
clientResponse.successResponse =
JsonConvert.DeserializeObject<T>(result.Content.ReadAsStringAsync().Result);
JsonConvert.DeserializeObject<T>(result.Content.ReadAsStringAsync().Result, SerializerSettings);
}
}
catch (Exception e)
Expand Down

0 comments on commit f2d6487

Please sign in to comment.