Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.Text.Json Serialization Support in .NET SDK Objects #3033

Merged
merged 37 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
9b040c7
moved Wholesome tests to their own namespace, for test output clarity
jar-stripe Nov 15, 2024
64908c5
added STJ attributes to base classes
jar-stripe Nov 15, 2024
aa40386
added STJ attributes to generated types
jar-stripe Nov 15, 2024
34a0381
added/updated wholesome tests to help us ensure correct system text j…
jar-stripe Nov 21, 2024
de5b0c3
replaced own UnixEpoch with DateTimeUtils
jar-stripe Nov 21, 2024
b3512f5
added additional system text json attributes
jar-stripe Nov 21, 2024
70f0327
updated wholesome tests
jar-stripe Nov 25, 2024
ed9ab01
added stj attributes to manually maintained classes
jar-stripe Nov 25, 2024
a158eb5
updated DontSerializeNullDeletedAttrs test to check for STJ equivalent
jar-stripe Nov 25, 2024
6109137
updated attributes for generated classes
jar-stripe Nov 26, 2024
a48e2ca
removed TODO
jar-stripe Nov 26, 2024
c79ed0d
added JsonConverter attributes to interfaces and ExpandableField
jar-stripe Nov 26, 2024
0da3ac5
refactored tests, cleared todos, and cleaned up code
jar-stripe Nov 26, 2024
d5ce297
Merge branch 'master' into jar/coexist-system-text-json
jar-stripe Nov 27, 2024
2767ba8
reverted accidental checkin
jar-stripe Nov 27, 2024
177b59b
Merge branch 'jar/coexist-system-text-json' of github.com:stripe/stri…
jar-stripe Nov 27, 2024
27d6fef
updated generated files
jar-stripe Nov 27, 2024
7e06bd2
added STJMemberSerializationOptIn custom converter factory to impleme…
jar-stripe Nov 28, 2024
fd8e14b
removed JsonInclude from SystemTextJsonUtils HasCorrectAttributes
jar-stripe Nov 28, 2024
de4e1a1
removed temporary TempProfiler class
jar-stripe Nov 28, 2024
6755f42
removed JsonInclude from manually maintained types and added OptIn co…
jar-stripe Nov 28, 2024
33f0560
rewrote STJStripeObjectConverter as a factory, and moved the JsonConv…
jar-stripe Nov 28, 2024
476ef07
removed all updates to generated files; this commit should contain on…
jar-stripe Dec 5, 2024
769340b
generated file updates with STJ support
jar-stripe Dec 5, 2024
ba81e81
removed changes to generated files (again)
jar-stripe Dec 5, 2024
04f886d
empty commit; this should show only manually modified files
jar-stripe Dec 5, 2024
d6f4322
added generated files with STJ support (again)
jar-stripe Dec 5, 2024
a1d5caa
Revert "added generated files with STJ support (again)"
jar-stripe Dec 5, 2024
dbe04ba
Merge remote-tracking branch 'origin/beta' into jar/coexist-system-te…
jar-stripe Dec 5, 2024
682c813
removed old commented code
jar-stripe Dec 5, 2024
68e1b90
added custom converter for V2 events, to ensure lists of polymorphic …
jar-stripe Dec 7, 2024
8b37706
added comments to explain Serialization and RawJObject limitations
jar-stripe Dec 9, 2024
b45793b
Update README.md
jar-stripe Dec 9, 2024
3ff9188
Update README.md
jar-stripe Dec 9, 2024
8d10b56
Merge branch 'beta' into jar/coexist-system-text-json
jar-stripe Dec 9, 2024
b116629
correted mistake in method doc
jar-stripe Dec 9, 2024
86560fc
updated generated code to include system.text.json attributes
jar-stripe Dec 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Stripe.net/Entities/Accounts/AccountSettingsDeclineOn.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
namespace Stripe
{
using Newtonsoft.Json;
#if NET6_0_OR_GREATER
using STJS = System.Text.Json.Serialization;
#endif

public class AccountSettingsDeclineOn : StripeEntity<AccountSettingsDeclineOn>
{
[JsonProperty("avs_failure")]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("avs_failure")]
#endif
public bool AvsFailure { get; set; }

[JsonProperty("cvc_failure")]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("cvc_failure")]
#endif
public bool CvcFailure { get; set; }
}
}
12 changes: 12 additions & 0 deletions src/Stripe.net/Entities/Balance/BalanceAmount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,28 @@ namespace Stripe
{
using System.Collections.Generic;
using Newtonsoft.Json;
#if NET6_0_OR_GREATER
using STJS = System.Text.Json.Serialization;
#endif

public class BalanceAmount : StripeEntity<BalanceAmount>
{
[JsonProperty("amount")]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("amount")]
#endif
public long Amount { get; set; }

[JsonProperty("currency")]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("currency")]
#endif
public string Currency { get; set; }

[JsonProperty("source_types")]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("source_types")]
#endif
public Dictionary<string, long> SourceTypes { get; set; }
}
}
21 changes: 21 additions & 0 deletions src/Stripe.net/Entities/Charges/ChargeLevel3LineItem.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,46 @@
namespace Stripe
{
using Newtonsoft.Json;
#if NET6_0_OR_GREATER
using STJS = System.Text.Json.Serialization;
#endif

public class ChargeLevel3LineItem : StripeEntity<ChargeLevel3LineItem>
{
[JsonProperty("discount_amount")]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("discount_amount")]
#endif
public long? DiscountAmount { get; set; }

[JsonProperty("product_code")]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("product_code")]
#endif
public string ProductCode { get; set; }

[JsonProperty("product_description")]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("product_description")]
#endif
public string ProductDescription { get; set; }

[JsonProperty("quantity")]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("quantity")]
#endif
public long? Quantity { get; set; }

[JsonProperty("tax_amount")]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("tax_amount")]
#endif
public long? TaxAmount { get; set; }

[JsonProperty("unit_cost")]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("unit_cost")]
#endif
public long? UnitCost { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,46 @@
namespace Stripe
{
using Newtonsoft.Json;
#if NET6_0_OR_GREATER
using STJS = System.Text.Json.Serialization;
#endif

public class ChargePaymentMethodDetailsBitcoin : StripeEntity<ChargePaymentMethodDetailsBitcoin>
{
[JsonProperty("address")]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("address")]
#endif
public string Address { get; set; }

[JsonProperty("amount")]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("amount")]
#endif
public long? Amount { get; set; }

[JsonProperty("amount_charged")]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("amount_charged")]
#endif
public long? AmountCharged { get; set; }

[JsonProperty("amount_received")]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("amount_received")]
#endif
public long? AmountReceived { get; set; }

[JsonProperty("amount_returned")]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("amount_returned")]
#endif
public long? AmountReturned { get; set; }

[JsonProperty("refund_address")]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("refund_address")]
#endif
public string RefundAddress { get; set; }
}
}
12 changes: 12 additions & 0 deletions src/Stripe.net/Entities/Events/EventData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ namespace Stripe
{
using Newtonsoft.Json;
using Stripe.Infrastructure;
#if NET6_0_OR_GREATER
using STJS = System.Text.Json.Serialization;
#endif

public class EventData : StripeEntity<EventData>
{
Expand All @@ -12,13 +15,19 @@ public class EventData : StripeEntity<EventData>
/// </summary>
[JsonProperty("object")]
[JsonConverter(typeof(StripeObjectConverter))]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("object")]
helenye-stripe marked this conversation as resolved.
Show resolved Hide resolved
#endif
public IHasObject Object { get; set; }

/// <summary>
/// Object containing the names of the attributes that have changed, and their previous
/// values (sent along only with *.updated events).
/// </summary>
[JsonProperty("previous_attributes")]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("previous_attributes")]
#endif
public dynamic PreviousAttributes { get; set; }

/// <summary>
Expand All @@ -27,6 +36,9 @@ public class EventData : StripeEntity<EventData>
/// library does not have a concrete type.
/// </summary>
[JsonIgnore]
#if NET6_0_OR_GREATER
[STJS.JsonIgnore]
#endif
public dynamic RawObject { get; set; }
}
}
7 changes: 7 additions & 0 deletions src/Stripe.net/Entities/ExpandableField.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
namespace Stripe
{
using System;
#if NET6_0_OR_GREATER
using Stripe.Infrastructure;
using STJS = System.Text.Json.Serialization;
#endif

/// <summary>Represents a generic expandable field.</summary>
/// <typeparam name="T">Type of the field when expanded.</typeparam>
#if NET6_0_OR_GREATER
[STJS.JsonConverter(typeof(STJExpandableFieldConverterFactory))]
#endif
public class ExpandableField<T> : IExpandableField<T>
where T : IHasId
{
Expand Down
19 changes: 19 additions & 0 deletions src/Stripe.net/Entities/Invoices/InvoiceDiscountAmount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,37 @@ namespace Stripe
{
using Newtonsoft.Json;
using Stripe.Infrastructure;
#if NET6_0_OR_GREATER
using STJS = System.Text.Json.Serialization;
#endif

#if NET6_0_OR_GREATER
[STJS.JsonConverter(typeof(STJMemberSerializationOptIn))]
#endif
public class InvoiceDiscountAmount : StripeEntity<InvoiceDiscountAmount>
{
[JsonProperty("amount")]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("amount")]
#endif
public long Amount { get; set; }

#region Expandable Discount

[JsonIgnore]
#if NET6_0_OR_GREATER
[STJS.JsonIgnore]
#endif
public string DiscountId
{
get => this.InternalDiscount?.Id;
set => this.InternalDiscount = SetExpandableFieldId(value, this.InternalDiscount);
}

[JsonIgnore]
#if NET6_0_OR_GREATER
[STJS.JsonIgnore]
#endif
public Discount Discount
{
get => this.InternalDiscount?.ExpandedObject;
Expand All @@ -26,6 +41,10 @@ public Discount Discount

[JsonProperty("discount")]
[JsonConverter(typeof(ExpandableFieldConverter<Discount>))]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("discount")]
[STJS.JsonConverter(typeof(STJExpandableFieldConverter<Discount>))]
#endif
internal ExpandableField<Discount> InternalDiscount { get; set; }
#endregion
}
Expand Down
28 changes: 28 additions & 0 deletions src/Stripe.net/Entities/Invoices/InvoiceTaxAmount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,31 @@ namespace Stripe
{
using Newtonsoft.Json;
using Stripe.Infrastructure;
#if NET6_0_OR_GREATER
using STJS = System.Text.Json.Serialization;
#endif

#if NET6_0_OR_GREATER
[STJS.JsonConverter(typeof(STJMemberSerializationOptIn))]
helenye-stripe marked this conversation as resolved.
Show resolved Hide resolved
#endif
public class InvoiceTaxAmount : StripeEntity<InvoiceTaxAmount>
{
/// <summary>
/// The amount, in cents (or local equivalent), of the tax.
/// </summary>
[JsonProperty("amount")]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("amount")]
#endif
public long Amount { get; set; }

/// <summary>
/// Whether this tax amount is inclusive or exclusive.
/// </summary>
[JsonProperty("inclusive")]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("inclusive")]
#endif
public bool Inclusive { get; set; }

#region Expandable TaxRate
Expand All @@ -24,6 +36,9 @@ public class InvoiceTaxAmount : StripeEntity<InvoiceTaxAmount>
/// The tax rate that was applied to get this tax amount.
/// </summary>
[JsonIgnore]
#if NET6_0_OR_GREATER
[STJS.JsonIgnore]
#endif
public string TaxRateId
{
get => this.InternalTaxRate?.Id;
Expand All @@ -37,6 +52,9 @@ public string TaxRateId
/// For more information, see the <a href="https://stripe.com/docs/expand">expand documentation</a>.
/// </summary>
[JsonIgnore]
#if NET6_0_OR_GREATER
[STJS.JsonIgnore]
#endif
public TaxRate TaxRate
{
get => this.InternalTaxRate?.ExpandedObject;
Expand All @@ -45,6 +63,10 @@ public TaxRate TaxRate

[JsonProperty("tax_rate")]
[JsonConverter(typeof(ExpandableFieldConverter<TaxRate>))]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("tax_rate")]
[STJS.JsonConverter(typeof(STJExpandableFieldConverter<TaxRate>))]
#endif
internal ExpandableField<TaxRate> InternalTaxRate { get; set; }
#endregion

Expand All @@ -58,12 +80,18 @@ public TaxRate TaxRate
/// <c>standard_rated</c>, <c>taxable_basis_reduced</c>, or <c>zero_rated</c>.
/// </summary>
[JsonProperty("taxability_reason")]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("taxability_reason")]
#endif
public string TaxabilityReason { get; set; }

/// <summary>
/// The amount on which tax is calculated, in cents (or local equivalent).
/// </summary>
[JsonProperty("taxable_amount")]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("taxable_amount")]
#endif
public long? TaxableAmount { get; set; }
}
}
6 changes: 6 additions & 0 deletions src/Stripe.net/Entities/OAuth/OAuthDeauthorize.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
namespace Stripe
{
using Newtonsoft.Json;
#if NET6_0_OR_GREATER
using STJS = System.Text.Json.Serialization;
#endif

public class OAuthDeauthorize : StripeEntity<OAuthDeauthorize>
{
Expand All @@ -10,6 +13,9 @@ public class OAuthDeauthorize : StripeEntity<OAuthDeauthorize>
/// returned, the revocation was successful.
/// </summary>
[JsonProperty("stripe_user_id")]
#if NET6_0_OR_GREATER
[STJS.JsonPropertyName("stripe_user_id")]
#endif
public string StripeUserId { get; set; }
}
}
Loading
Loading