Skip to content

[Bug] Generator emits non-nullable DateTimeOffset deserialization for nullable date fields #1795

Description

@gcatanese

Context

In auto-generated model classes, DateTimeOffset? fields (optional dates) are deserialized using the non-nullable type:

createdAt = new Option<DateTimeOffset?>(JsonSerializer.Deserialize<DateTimeOffset>(ref utf8JsonReader, jsonSerializerOptions));

System.Text.Json throws a JsonException when the JSON value is null and the target type is non-nullable DateTimeOffset. This pattern exists in 174 occurrences across all services (ConfigurationWebhooks, Transfers, BalancePlatform, Checkout, etc.).

This is low priority since the Adyen API typically omits optional date fields rather than sending explicit null, but it is a latent runtime crash waiting to happen.

Proposed Change

Update the code generator template to use the nullable type in Deserialize<T> when the target property is T?:

createdAt = new Option<DateTimeOffset?>(JsonSerializer.Deserialize<DateTimeOffset?>(ref utf8JsonReader, jsonSerializerOptions));

The fix belongs in the adyen-sdk-automation generator template, not in the library itself, since these files are auto-generated and manual edits would be overwritten.

Benefit

Prevents a JsonException crash when an optional date field is explicitly present as null in a webhook payload.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions