fix(java): backport nullable array validation fix#214
Merged
Conversation
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
Contributor
Author
// 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()));
} |
NextFire
commented
May 6, 2026
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())); | ||
| } |
Contributor
Author
There was a problem hiding this comment.
This is the actual change: && !jsonObj.get("{{{baseName}}}").isJsonNull() addition
tnion-criteo
approved these changes
May 7, 2026
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.
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