Support Bare deserialization and update tests#1688
Open
gcatanese wants to merge 44 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request enables "bare" serialization and deserialization for Adyen SDK models by adding class-level [JsonConverter] attributes, allowing System.Text.Json to automatically discover the appropriate converters without requiring explicit options. The changes include updates to the model templates, new unit tests for bare serialization, and documentation updates. Review feedback indicates that property-level [JsonConverter] attributes for byte arrays and DateOnly types are currently ignored by the manual class-level converter implementations, which may lead to inconsistent data handling between bare and DI-configured serialization modes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #1613 #1687
This PR implements the proposed solution from issue #1613: Support bare
JsonSerializer.Deserialize<T>(json)without requiring SDK-internalJsonSerializerOptions.Problem
Since v34.0.0, custom
JsonConverter<T>instances for each model were registered only inHostConfigurationvia DI. This meant that callingJsonSerializer.Deserialize<T>(json)without the SDK's options produced incorrect results — missing optional-field tracking, wrong date formats, and broken byte array handling. Affected scenarios include unit tests, webhook processing, caching layers, and message queues.Solution
Made all generated models self-describing to
System.Text.Jsonby adding[JsonConverter(typeof(XJsonConverter))]attributes at the class level, so STJ discovers the correct converter automatically regardless of whichJsonSerializerOptions(if any) the caller supplies. Property-level[JsonConverter]attributes are also added forbyte[]andDateOnlyfields.Changes
templates-v7/csharp/libraries/generichost/modelGeneric.mustache— Added class-level[JsonConverter]attribute and property-level attributes forbyte[]andDateOnlytypes to the model template.templates-v7/csharp/libraries/generichost/model.mustache— Added missingusingforAdyen.Core.Convertersnamespace.Checkout,LEM,CapitalAdyen.Test/Core/Serialization/BareSerializationTests.cs— New test class covering bare serialize/deserialize round-trips forAmount,ThreeDSecureData,CheckoutPaymentMethod, and nested models without anyJsonSerializerOptions.Adyen.Test/Payment/PaymentTest.cs— Fixed existing test assertion: useTryGetPropertyinstead ofGetPropertyfor optional non-nullable fields that may be absent in the serialized output.README.md— Documented the new bare deserialization path and clarified when DI-provided options are still recommended (e.g. forbyte[]fields withByteArrayConverter).Backwards compatibility
No breaking changes. STJ gives precedence to type-level
[JsonConverter]attributes over converters registered inJsonSerializerOptions, so the existing DI-based pipeline continues to work exactly as before.Known limitation
byte[]fields (e.g.ThreeDSecureData.Cavv) behave differently in bare mode vs. DI mode due to howByteArrayConverteris currently implemented. This is documented in the README and tracked separately in #1687.