Skip to content

Commit

Permalink
Merge pull request #805 from clement911/invalid-date-fix2
Browse files Browse the repository at this point in the history
  • Loading branch information
nozzlegear authored Nov 10, 2022
2 parents d673073 + 4364622 commit e5cc7f9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 8 additions & 1 deletion ShopifySharp/Infrastructure/Serializer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using ShopifySharp.Converters;
using System;
using System.Collections.Generic;
Expand All @@ -25,8 +26,14 @@ private static JsonSerializerSettings CreateSettings()

public static string Serialize(object data) => JsonConvert.SerializeObject(data, CreateSettings());

public static object Deserialize(string json, Type objectType) => JsonConvert.DeserializeObject(json, objectType, CreateSettings());

public static T Deserialize<T>(string json) => JsonConvert.DeserializeObject<T>(json, CreateSettings());

public static object Deserialize(string json, Type objectType) => JsonConvert.DeserializeObject(json, objectType, CreateSettings());
public static T Deserialize<T>(string json, string rootElementPath)
{
var jToken = JObject.Parse(json).SelectToken(rootElementPath);
return jToken.ToObject<T>(JsonSerializer.Create(CreateSettings()));
}
}
}
3 changes: 1 addition & 2 deletions ShopifySharp/Services/ShopifyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@ protected async Task<RequestResult<T>> ExecuteRequestAsync<T>(RequestUri uri, Ht
// This method may fail when the method was Delete, which is intendend.
// Delete methods should not be parsing the response JSON and should instead
// be using the non-generic ExecuteRequestAsync.
var data = Serializer.Deserialize<JObject>(rawResult).SelectToken(rootElement);
result = data.ToObject<T>();
result = Serializer.Deserialize<T>(rawResult, rootElement);
}

return new RequestResult<T>(response, result, rawResult, ReadLinkHeader(response));
Expand Down

0 comments on commit e5cc7f9

Please sign in to comment.