ShopifySharp icon indicating copy to clipboard operation
ShopifySharp copied to clipboard

ShopifySharp.GraphQL.Customer not being deserialized from bulk operation query JSONL file

Open troyha opened this issue 5 months ago • 2 comments

When downloading the JSONL file for a bulk operation query with Customer data (and other data but have only made it to the Customer for now) and trying to deserialize the GraphQL Customer record to ShopifySharp.GraphQL.Customer I'm getting the following exception:

The JSON value could not be converted to System.Nullable`1[ShopifySharp.GraphQL.CurrencyCode]. Path: $.amountSpent.currencyCode | LineNumber: 0 | BytePositionInLine: 99.

Code:

private readonly JsonSerializerOptions _serializerOptions = new()
{
    PropertyNameCaseInsensitive = true,
    NumberHandling = System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString //Needed as number values are written as strings
};

//The downloaded content is a JSONL file and should be read line by line
using var stream = await response.Content.ReadAsStreamAsync();
using var reader = new StreamReader(stream);
string line;
while ((line = await reader.ReadLineAsync()) != null)
{
    // Deserialize the JSONL line into the appropriate object
    if (line.Contains("shopify\\/Customer"))
    {
        var customer = JsonSerializer.Deserialize<ShopifySharp.GraphQL.Customer>(line, _serializerOptions); //Exception here

Data (anonymised): "{"id":"gid:\/\/shopify\/Customer\/0000000000000","amountSpent":{"amount":"0.0","currencyCode":"AUD"},"createdAt":"2020-10-12T06:46:06Z","defaultAddress":{"city":"City","country":"Australia","countryCodeV2":"AU","province":"New South Wales","provinceCode":"NSW","zip":"0000"},"email":"[email protected]","firstName":"Test","lastOrder":null,"numberOfOrders":"0","updatedAt":"2023-11-16T09:42:31Z","verifiedEmail":false}"

ShopifySharp version: 6.23.0 Dotnet 8.0 Azure Functions v4 Isolated

Note sure if I am doing something wrong? Do I have to write a custom converter for each custom ShopifySharp.GraphQL type?

troyha avatar May 25 '25 12:05 troyha