vslee/IEXSharp

JsonConverter.Int64Converter can't handle null values

kewur opened this issue · 1 comments

kewur commented

Hi,

I'm using the Batch api to get a list of stock prices from the IntradayPrices endpoint. Some of the stocks returns "null" for fields such as volume from IEX, this in turn causes the Json Deserializer to throw an exception internally.

this is how I'm making the call

try { return await _batchService.BatchByMarketAsync(symbols, new[] { BatchType.IntradayPrices }, _fiveMinutesChartLatestPointArguments); } catch (JsonException exception) { Console.WriteLine(exception); }

an example symbol that fails is "AMER" which IEX cloud returns the following response,

  "AMER": {
    "intraday-prices": [
      {
        "date": "2020-11-20",
        "minute": "15:55",
        "label": null,
        "high": null,
        "low": null,
        "average": null,
        "volume": null,
        "notional": null,
        "numberOfTrades": null,
        "marketHigh": null,
        "marketLow": null,
        "marketAverage": null,
        "marketVolume": null,
        "marketNotional": null,
        "marketNumberOfTrades": null,
        "open": null,
        "close": null,
        "marketOpen": null,
        "marketClose": null,
        "changeOverTime": null,
        "marketChangeOverTime": null
      }
    ]
  }

Here is the stack trace,

 ---> System.Text.Json.JsonException: The JSON value could not be converted to System.Int64. Path: $.AMER.intraday-prices[0].volume | LineNumber: 0 | BytePositionInLine: 32105.
 ---> System.InvalidOperationException: Cannot get the value of a token type 'Null' as a number.
   at System.Text.Json.Utf8JsonReader.TryGetInt64(Int64& value)
   at System.Text.Json.Utf8JsonReader.GetInt64()
   at System.Text.Json.JsonPropertyInfoNotNullable`4.OnRead(ReadStack& state, Utf8JsonReader& reader)
   at System.Text.Json.JsonSerializer.HandleNull(Utf8JsonReader& reader, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadCore(JsonSerializerOptions options, Utf8JsonReader& reader, ReadStack& readStack)
   --- End of inner exception stack trace ---
   at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& readStack, Utf8JsonReader& reader, Exception ex)
   at System.Text.Json.JsonSerializer.ReadCore(JsonSerializerOptions options, Utf8JsonReader& reader, ReadStack& readStack)
   at System.Text.Json.JsonSerializer.ReadCore(Type returnType, JsonSerializerOptions options, Utf8JsonReader& reader)
   at System.Text.Json.JsonSerializer.Deserialize(String json, Type returnType, JsonSerializerOptions options)
   at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)
   at IEXSharp.Helper.ExecutorREST.ExecuteAsync[ReturnType](String urlPattern, NameValueCollection pathNVC, QueryStringBuilder qsb, Boolean forceUseSecretToken)
   --- End of inner exception stack trace ---
   at IEXSharp.Helper.ExecutorREST.ExecuteAsync[ReturnType](String urlPattern, NameValueCollection pathNVC, QueryStringBuilder qsb, Boolean forceUseSecretToken)
   at IEXSharp.Service.Cloud.CoreData.Batch.BatchService.BatchByMarketAsync(IEnumerable`1 symbols, IEnumerable`1 types, IReadOnlyDictionary`2 optionalParameters)
kewur commented

thank you!