diff --git a/src/Stripe.net/Infrastructure/JsonConverters/STJUnixDateTimeConverter.cs b/src/Stripe.net/Infrastructure/JsonConverters/STJUnixDateTimeConverter.cs
index 8fbf247152..31846445a0 100644
--- a/src/Stripe.net/Infrastructure/JsonConverters/STJUnixDateTimeConverter.cs
+++ b/src/Stripe.net/Infrastructure/JsonConverters/STJUnixDateTimeConverter.cs
@@ -5,6 +5,62 @@ namespace Stripe.Infrastructure
using System.Text.Json;
using System.Text.Json.Serialization;
+ ///
+ /// A JsonConverterFactory for use with DateTime and DateTime? implementations
+ /// to ensure we return a correctly typed custom converter.
+ ///
+#pragma warning disable SA1649 // File name should match first type name
+ internal class STJUnixDateTimeConverter : JsonConverterFactory
+#pragma warning restore SA1649 // File name should match first type name
+ {
+ public override bool CanConvert(Type typeToConvert)
+ {
+ return typeToConvert == typeof(DateTime) || typeToConvert == typeof(DateTime?);
+ }
+
+ public override JsonConverter CreateConverter(
+ Type type,
+ JsonSerializerOptions options)
+ {
+ if (type == typeof(DateTime?))
+ {
+ return new STJUnixNullableDateTimeConverterImpl();
+ }
+ else
+ {
+ return new STJUnixDateTimeConverterImpl();
+ }
+ }
+ }
+
+#pragma warning disable SA1402 // File may only contain a single type
+ internal class STJUnixNullableDateTimeConverterImpl : JsonConverter
+#pragma warning restore SA1402 // File may only contain a single type
+ {
+ private static readonly STJUnixDateTimeConverterImpl BaseConverter = new STJUnixDateTimeConverterImpl();
+
+ public override DateTime? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
+ {
+ if (reader.TokenType == JsonTokenType.Null)
+ {
+ return null;
+ }
+
+ return BaseConverter.Read(ref reader, typeToConvert, options);
+ }
+
+ public override void Write(Utf8JsonWriter writer, DateTime? value, JsonSerializerOptions options)
+ {
+ if (value == null)
+ {
+ writer.WriteNullValue();
+ return;
+ }
+
+ BaseConverter.Write(writer, value.Value, options);
+ }
+ }
+
///
/// Converts a to and from Unix epoch time.
///
@@ -13,7 +69,9 @@ namespace Stripe.Infrastructure
/// Newtonsoft.Json 11.0. Once we bump the minimum version of Newtonsoft.Json to 11.0, we can
/// start using the provided converter and get rid of this class.
///
- internal class STJUnixDateTimeConverter : JsonConverter
+#pragma warning disable SA1402 // File may only contain a single type
+ internal class STJUnixDateTimeConverterImpl : JsonConverter
+#pragma warning restore SA1402 // File may only contain a single type
{
///
/// Reads the JSON representation of the object.
diff --git a/src/Stripe.net/Infrastructure/JsonConverters/SerializablePropertyCache.cs b/src/Stripe.net/Infrastructure/JsonConverters/SerializablePropertyCache.cs
index bacfe7b40c..bd092c60e9 100644
--- a/src/Stripe.net/Infrastructure/JsonConverters/SerializablePropertyCache.cs
+++ b/src/Stripe.net/Infrastructure/JsonConverters/SerializablePropertyCache.cs
@@ -69,6 +69,7 @@ internal class SerializablePropertyInfo
private static MethodInfo createGetDelegateMethod = typeof(SerializablePropertyInfo).GetMethod("CreateGetDelegate", BindingFlags.Static | BindingFlags.NonPublic);
private static MethodInfo createSetDelegateMethod = typeof(SerializablePropertyInfo).GetMethod("CreateSetDelegate", BindingFlags.Static | BindingFlags.NonPublic);
private static MethodInfo getConverterForTypeMethod = typeof(SerializablePropertyInfo).GetMethod("GetConverterForType", BindingFlags.Static | BindingFlags.NonPublic);
+ private static MethodInfo getConverterFromFactoryMethod = typeof(SerializablePropertyInfo).GetMethod("GetConverterFromFactory", BindingFlags.Static | BindingFlags.NonPublic);
private static MethodInfo getDefaultConverterMethod = typeof(SerializablePropertyInfo).GetMethod("GetDefaultConverter", BindingFlags.Static | BindingFlags.NonPublic);
private Func