Skip to content

fix(java): backport nullable array validation fix#214

Merged
NextFire merged 1 commit intomainfrom
fix/nullable-arrays
May 11, 2026
Merged

fix(java): backport nullable array validation fix#214
NextFire merged 1 commit intomainfrom
fix/nullable-arrays

Conversation

@NextFire
Copy link
Copy Markdown
Contributor

@NextFire NextFire commented May 6, 2026

The OAS already marks nullable arrays such as
SellerCampaignMessage.suspensionReasons as nullable: true, but OpenAPI Generator 6.3.0's Java Gson template rejects explicit JSON null values during validation.

Add a local okhttp-gson POJO template override with the 7.0.1 null guard so optional array fields accept JSON null without upgrading the generator version.

Fix criteo/criteo-api-java-sdk#23

The OAS already marks nullable arrays such as
SellerCampaignMessage.suspensionReasons as nullable: true, but OpenAPI
Generator 6.3.0's Java Gson template rejects explicit JSON null values
during validation.

Add a local okhttp-gson POJO template override with the 7.0.1 null guard
so optional array fields accept JSON null without upgrading the
generator version.

Fix criteo/criteo-api-java-sdk#23
@NextFire
Copy link
Copy Markdown
Contributor Author

NextFire commented May 6, 2026

       // ensure the optional json data is an array if present
-      if (jsonObj.get("suspensionReasons") != null && !jsonObj.get("suspensionReasons").isJsonArray()) {
+      if (jsonObj.get("suspensionReasons") != null && !jsonObj.get("suspensionReasons").isJsonNull() && !jsonObj.get("suspensionReasons").isJsonArray()) {
         throw new IllegalArgumentException(String.format("Expected the field `suspensionReasons` to be an array in the JSON string but got `%s`", jsonObj.get("suspensionReasons").toString()));
       }

Comment on lines +512 to +516
// ensure the optional json data is an array if present
{{!-- https://github.com/criteo/criteo-api-java-sdk/issues/23 --}}
if (jsonObj.get("{{{baseName}}}") != null && !jsonObj.get("{{{baseName}}}").isJsonNull() && !jsonObj.get("{{{baseName}}}").isJsonArray()) {
throw new IllegalArgumentException(String.format("Expected the field `{{{baseName}}}` to be an array in the JSON string but got `%s`", jsonObj.get("{{{baseName}}}").toString()));
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the actual change: && !jsonObj.get("{{{baseName}}}").isJsonNull() addition

@NextFire NextFire merged commit fe633db into main May 11, 2026
1 check passed
@NextFire NextFire deleted the fix/nullable-arrays branch May 11, 2026 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue with mapping Java response body of Seller Campaign after Update operation

2 participants