Skip to content

[Bug] Required TypeEnum deserializer silently accepts null, violating non-nullable contract #1678

Description

@gcatanese

Context

In the generated JsonConverter for models with a required inner TypeEnum discriminator (e.g. CheckoutDelegatedAuthenticationAction, CheckoutThreeDS2Action, CheckoutRedirectAction), a JSON payload containing "type": null is not rejected as it should be. The current deserialization path:

  1. Reads typeRawValue as null via utf8JsonReader.GetString()
  2. Calls TypeEnum.FromStringOrDefault(null) → returns null
  3. Falls back to implicit cast (TypeEnum)(string?)null → also returns null
  4. Stores null in new Option<TypeEnum?>(null)IsSet becomes true
  5. The required-field guard if (!type.IsSet) passes silently
  6. Assigns null to the non-nullable TypeEnum Type property via type.Value!

This violates the non-nullable contract on Type and can lead to a NullReferenceException downstream.

Proposed Change

In JsonConverter.mustache, when reading a required enum property, explicitly check for a null raw value before constructing the Option and throw a descriptive exception:

case "type":
    string? typeRawValue = utf8JsonReader.GetString();
    if (typeRawValue == null)
        throw new JsonException("The 'type' property cannot be null for CheckoutDelegatedAuthenticationAction.");
    type = new Option<TypeEnum?>(TypeEnum.FromStringOrDefault(typeRawValue) ?? (TypeEnum)typeRawValue);
    break;

This pattern should be applied to all required enum fields in the template, not just discriminators.

Benefit

Prevents null from silently bypassing the required-field guard and being assigned to a non-nullable property, replacing a potential NullReferenceException at call-site with a clear JsonException at deserialization time.

Notes

Low priority issue.

The Adyen API will never send "type": null in a valid response, so the bug only affects malformed or manually crafted JSON payloads and edge cases in testing. When triggered, the consequence is a NullReferenceException at a later access site rather than a clear JsonException at deserialization time, making the failure harder to diagnose.
It would be a valid improvement but it doesn't affect the API behaviour.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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