Skip to content

Add StringEnum JSON converters for batch jobs#3300

Merged
mbroshi-stripe merged 2 commits intomasterfrom
mbroshi/batch_jobs
Mar 24, 2026
Merged

Add StringEnum JSON converters for batch jobs#3300
mbroshi-stripe merged 2 commits intomasterfrom
mbroshi/batch_jobs

Conversation

@mbroshi-stripe
Copy link
Copy Markdown
Contributor

@mbroshi-stripe mbroshi-stripe commented Jan 29, 2026

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, BatchJobEndpointPath is a StringEnum — the first StringEnum type 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?

  • Added STJStringEnumConverterFactory (STJ) and NewtonsoftStringEnumConverter (Newtonsoft) to serialize StringEnum subclasses as plain strings
  • Added [STJS.JsonConverter(typeof(STJStringEnumConverterFactory))] to all concrete StringEnum subclasses — STJ does not inherit converter attributes from base classes, so each subclass needs its own
  • Added [Newtonsoft.Json.JsonConverter(typeof(NewtonsoftStringEnumConverter))] to the StringEnum base class — Newtonsoft does inherit, so base class placement works
  • Added [JsonPropertyName("Value")] to StringEnum.Value for STJ serialization

@mbroshi-stripe mbroshi-stripe changed the base branch from master to beta January 29, 2026 22:25
@mbroshi-stripe mbroshi-stripe force-pushed the mbroshi/batch_jobs branch 3 times, most recently from a3f6cb6 to 4565318 Compare March 23, 2026 21:31
@mbroshi-stripe mbroshi-stripe changed the base branch from beta to latest-codegen-beta March 23, 2026 21:32
Base automatically changed from latest-codegen-beta to beta March 23, 2026 23:12
Copy link
Copy Markdown
Contributor

@jar-stripe jar-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The general direction is right but we need to make some changes to the JSON configuration and code.

Comment thread src/Stripe.net/Infrastructure/Public/StripeConfiguration.cs Outdated
Comment thread src/Stripe.net/Services/Accounts/AccountService.cs Outdated
Comment thread src/Stripe.net/Services/_base/StringEnum.cs Outdated
Copy link
Copy Markdown
Contributor

@jar-stripe jar-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mbroshi-stripe mbroshi-stripe changed the title Mbroshi/batch jobs Add batch job support: SerializeBatch methods, StringEnum JSON converters, and V2 BatchJob service Mar 24, 2026
@mbroshi-stripe mbroshi-stripe changed the title Add batch job support: SerializeBatch methods, StringEnum JSON converters, and V2 BatchJob service Add SerializeBatch methods and StringEnum JSON converters for batch jobs Mar 24, 2026
@mbroshi-stripe mbroshi-stripe marked this pull request as ready for review March 24, 2026 04:20
@mbroshi-stripe mbroshi-stripe requested a review from a team as a code owner March 24, 2026 04:20
@mbroshi-stripe mbroshi-stripe requested review from Copilot and jar-stripe and removed request for a team March 24, 2026 04:20
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 : StringEnum and updated batch job endpoint options to use it.
  • Added STJ + Newtonsoft converters to serialize StringEnum subclasses as plain strings, and annotated concrete StringEnum subclasses 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.

Comment thread src/Stripe.net/Services/Customers/CustomerService.cs Outdated
Comment thread src/Stripe.net/Services/Customers/CustomerService.cs Outdated
Comment thread src/Stripe.net/Services/Invoices/InvoiceService.cs Outdated
Comment thread src/Stripe.net/Services/Invoices/InvoiceService.cs Outdated
Comment thread src/StripeTests/Services/Customers/CustomerServiceSerializeBatchTest.cs Outdated
Comment thread src/Stripe.net/Services/Accounts/AccountService.cs Outdated
Comment thread src/Stripe.net/Services/Accounts/AccountService.cs Outdated
Comment thread src/Stripe.net/Services/PromotionCodes/PromotionCodeService.cs Outdated
Copy link
Copy Markdown
Contributor

@jar-stripe jar-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG! Non blocking but as a follow up, I think we should add more generated example tests for the batch job apis

Comment thread src/Stripe.net/Services/Accounts/AccountService.cs Outdated
@mbroshi-stripe mbroshi-stripe changed the base branch from beta to master March 24, 2026 20:21
@mbroshi-stripe mbroshi-stripe changed the title Add SerializeBatch methods and StringEnum JSON converters for batch jobs Add StringEnum JSON converters for batch jobs Mar 24, 2026
@mbroshi-stripe mbroshi-stripe enabled auto-merge (squash) March 24, 2026 21:35
@mbroshi-stripe mbroshi-stripe merged commit b44e136 into master Mar 24, 2026
8 of 9 checks passed
@mbroshi-stripe mbroshi-stripe deleted the mbroshi/batch_jobs branch March 24, 2026 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants