Add StringEnum JSON converters for batch jobs#3300
Conversation
a3f6cb6 to
4565318
Compare
jar-stripe
left a comment
There was a problem hiding this comment.
The general direction is right but we need to make some changes to the JSON configuration and code.
a3a8796 to
6822239
Compare
jar-stripe
left a comment
There was a problem hiding this comment.
This looks good; I have a small aversion to the fully qualified names (vs using statements) for e.g. System.Text.Json or Stripe.Infrastructure but otherwise happy to approve once this comes out of draft.
There was a problem hiding this comment.
Pull request overview
Adds client-side helpers and serialization support needed for Stripe’s V2 Batch Jobs API: generating JSONL request lines for bulk operations and ensuring StringEnum values serialize as plain strings under both Newtonsoft.Json and System.Text.Json.
Changes:
- Added
SerializeBatch*methods on several v1 services to emit per-item JSON suitable for JSONL batch submissions. - Introduced
BatchJobEndpointPath : StringEnumand updated batch job endpoint options to use it. - Added STJ + Newtonsoft converters to serialize
StringEnumsubclasses as plain strings, and annotated concreteStringEnumsubclasses for STJ.
Reviewed changes
Copilot reviewed 33 out of 33 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
| src/StripeTests/Services/GeneratedExamplesTest.cs | Updates generated example to use the new typed BatchJobEndpointPath. |
| src/StripeTests/Services/Customers/CustomerServiceSerializeBatchTest.cs | Adds tests for CustomerService.SerializeBatchUpdate JSON structure/null/context behavior. |
| src/Stripe.net/Services/_base/StringEnum.cs | Adds base Newtonsoft converter + STJ property annotation for StringEnum. |
| src/Stripe.net/Services/V2/Core/BatchJobs/BatchJobEndpointPath.cs | Adds typed StringEnum wrapper for supported batch endpoint paths. |
| src/Stripe.net/Services/V2/Core/BatchJobs/BatchJobCreateEndpointOptions.cs | Changes Path from string to BatchJobEndpointPath. |
| src/Stripe.net/Services/Tax/Registrations/RegistrationExpiresAt.cs | Annotates concrete StringEnum subclass with STJ converter. |
| src/Stripe.net/Services/Tax/Registrations/RegistrationActiveFrom.cs | Annotates concrete StringEnum subclass with STJ converter. |
| src/Stripe.net/Services/Subscriptions/SubscriptionTrialEnd.cs | Annotates concrete StringEnum subclass with STJ converter. |
| src/Stripe.net/Services/Subscriptions/SubscriptionService.cs | Adds SerializeBatchMigrate / SerializeBatchUpdate JSONL helpers. |
| src/Stripe.net/Services/Subscriptions/SubscriptionCancelAt.cs | Annotates concrete StringEnum subclass with STJ converter. |
| src/Stripe.net/Services/Subscriptions/SubscriptionBillingCycleAnchor.cs | Annotates concrete StringEnum subclass with STJ converter. |
| src/Stripe.net/Services/SubscriptionSchedules/SubscriptionScheduleStartDate.cs | Annotates concrete StringEnum subclass with STJ converter. |
| src/Stripe.net/Services/SubscriptionSchedules/SubscriptionScheduleService.cs | Adds SerializeBatchCancel / SerializeBatchCreate / SerializeBatchUpdate JSONL helpers. |
| src/Stripe.net/Services/SubscriptionSchedules/SubscriptionSchedulePhaseTrialEnd.cs | Annotates concrete StringEnum subclass with STJ converter. |
| src/Stripe.net/Services/SubscriptionSchedules/SubscriptionSchedulePhaseStartDate.cs | Annotates concrete StringEnum subclass with STJ converter. |
| src/Stripe.net/Services/SubscriptionSchedules/SubscriptionSchedulePhaseEndDate.cs | Annotates concrete StringEnum subclass with STJ converter. |
| src/Stripe.net/Services/Quotes/QuoteSubscriptionDataEffectiveDate.cs | Annotates concrete StringEnum subclass with STJ converter. |
| src/Stripe.net/Services/PromotionCodes/PromotionCodeService.cs | Adds SerializeBatchCreate / SerializeBatchUpdate JSONL helpers. |
| src/Stripe.net/Services/Prices/PriceTierUpTo.cs | Annotates concrete StringEnum subclass with STJ converter. |
| src/Stripe.net/Services/Plans/PlanTierUpTo.cs | Annotates concrete StringEnum subclass with STJ converter. |
| src/Stripe.net/Services/Invoices/UpcomingInvoiceSubscriptionResumeAt.cs | Annotates concrete StringEnum subclass with STJ converter. |
| src/Stripe.net/Services/Invoices/InvoiceSubscriptionDetailsTrialEnd.cs | Annotates concrete StringEnum subclass with STJ converter. |
| src/Stripe.net/Services/Invoices/InvoiceSubscriptionDetailsCancelAt.cs | Annotates concrete StringEnum subclass with STJ converter. |
| src/Stripe.net/Services/Invoices/InvoiceSubscriptionDetailsBillingCycleAnchor.cs | Annotates concrete StringEnum subclass with STJ converter. |
| src/Stripe.net/Services/Invoices/InvoiceService.cs | Adds SerializeBatchPay / SerializeBatchUpdate JSONL helpers. |
| src/Stripe.net/Services/Invoices/InvoiceScheduleDetailsPhaseTrialEnd.cs | Annotates concrete StringEnum subclass with STJ converter. |
| src/Stripe.net/Services/Invoices/InvoiceScheduleDetailsPhaseStartDate.cs | Annotates concrete StringEnum subclass with STJ converter. |
| src/Stripe.net/Services/Invoices/InvoiceScheduleDetailsPhaseEndDate.cs | Annotates concrete StringEnum subclass with STJ converter. |
| src/Stripe.net/Services/Customers/CustomerService.cs | Adds SerializeBatchUpdate JSONL helper. |
| src/Stripe.net/Services/Accounts/AccountSettingsPayoutsScheduleDelayDays.cs | Annotates concrete StringEnum subclass with STJ converter. |
| src/Stripe.net/Services/Accounts/AccountService.cs | Adds SerializeBatchUpdate JSONL helper. |
| src/Stripe.net/Infrastructure/JsonConverters/STJStringEnumConverterFactory.cs | Adds STJ converter factory to serialize StringEnum as a string. |
| src/Stripe.net/Infrastructure/JsonConverters/NewtonsoftStringEnumConverter.cs | Adds Newtonsoft converter to serialize StringEnum as a string. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
jar-stripe
left a comment
There was a problem hiding this comment.
LG! Non blocking but as a follow up, I think we should add more generated example tests for the batch job apis
1c40491 to
c8ed15b
Compare
Why?
Stripe's V2 Batch Jobs API allows performing bulk operations (e.g., updating thousands of customers or subscriptions) in a single API call. The client needs to serialize individual request params into JSONL lines locally before submitting them. Additionally,
BatchJobEndpointPathis aStringEnum— the firstStringEnumtype used in V2 JSON-serialized requests — which requires dedicated JSON converters to serialize as a plain string rather than an object. While this feature is still only in public preview, we need certain prerequisite changes to be made in GA to handle public and private preview features.What?
STJStringEnumConverterFactory(STJ) andNewtonsoftStringEnumConverter(Newtonsoft) to serializeStringEnumsubclasses as plain strings[STJS.JsonConverter(typeof(STJStringEnumConverterFactory))]to all concreteStringEnumsubclasses — STJ does not inherit converter attributes from base classes, so each subclass needs its own[Newtonsoft.Json.JsonConverter(typeof(NewtonsoftStringEnumConverter))]to theStringEnumbase class — Newtonsoft does inherit, so base class placement works[JsonPropertyName("Value")]toStringEnum.Valuefor STJ serialization