AllOf without mapping not working#1718
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements support for bare serialization across Adyen SDK models by adding class-level [JsonConverter] attributes and updating byte array property handling. It includes a comprehensive set of new tests to verify serialization behavior without explicit options. The review feedback identifies a missing converter attribute in the Result model, suggests using static instances for ByteArrayConverter to improve efficiency, and recommends asserting the return values of TryGetProperty in tests for better failure diagnostics.
| using System.Text.Json.Serialization; | ||
| using System.ComponentModel.DataAnnotations; | ||
| using Adyen.Core; | ||
| using Adyen.Core.Converters; |
There was a problem hiding this comment.
The using Adyen.Core.Converters; statement was added, but the corresponding [JsonConverter(typeof(ResultJsonConverter))] attribute is missing from the Result class definition. This appears to be an oversight, as other model files in this pull request have both the using statement and the attribute added to support bare serialization and correct allOf handling.
| break; | ||
| case "cavv": | ||
| cavv = new Option<byte[]?>(JsonSerializer.Deserialize<byte[]>(ref utf8JsonReader, jsonSerializerOptions)!); | ||
| cavv = new Option<byte[]?>(new ByteArrayConverter().Read(ref utf8JsonReader, typeof(byte[]), jsonSerializerOptions)); |
There was a problem hiding this comment.
Instantiating new ByteArrayConverter() multiple times within the Read and Write methods is inefficient. Consider using a static instance of ByteArrayConverter or a local variable if multiple properties are processed. Additionally, ensure that ByteArrayConverter.Write handles null values safely, as it is now called manually when IsSet is true, even if the value itself is null (which could happen if a property was explicitly set to null).
| { | ||
| case "content": | ||
| content = new Option<byte[]?>(JsonSerializer.Deserialize<byte[]>(ref utf8JsonReader, jsonSerializerOptions)!); | ||
| content = new Option<byte[]?>(new ByteArrayConverter().Read(ref utf8JsonReader, typeof(byte[]), jsonSerializerOptions)); |
| lineItems[0].TryGetProperty("amountExcludingTax", out JsonElement amountExcludingTax); | ||
| lineItems[1].TryGetProperty("taxAmount", out JsonElement taxAmount); | ||
| Assert.AreEqual(0, amountExcludingTax.GetInt32()); | ||
| Assert.AreEqual(0, taxAmount.GetInt32()); |
There was a problem hiding this comment.
The return value of TryGetProperty should be asserted. If the property is missing from the JSON, amountExcludingTax will be an empty JsonElement, and the subsequent .GetInt32() call will throw an InvalidOperationException, making the test failure harder to diagnose.
Assert.IsTrue(lineItems[0].TryGetProperty("amountExcludingTax", out JsonElement amountExcludingTax));
Assert.IsTrue(lineItems[1].TryGetProperty("taxAmount", out JsonElement taxAmount));
Assert.AreEqual(0, amountExcludingTax.GetInt32());
Assert.AreEqual(0, taxAmount.GetInt32());
Fix #1717
WIP to address the handling of
allOfNote
Adyen.Test/mocks/sessionauthentication/create-session-request.jsontype value should beLegalEntity