mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-10 19:32:43 +00:00
Fix Java GSON client not accepting optional null arrays (#16213)
* Add check for null JSON array in GSON Java api client * Update samples
This commit is contained in:
committed by
GitHub
parent
36cb3ce6b9
commit
7a7309edb8
@@ -164,7 +164,7 @@ public class ArrayOfArrayOfNumberOnly {
|
||||
}
|
||||
JsonObject jsonObj = jsonElement.getAsJsonObject();
|
||||
// ensure the optional json data is an array if present
|
||||
if (jsonObj.get("ArrayArrayNumber") != null && !jsonObj.get("ArrayArrayNumber").isJsonArray()) {
|
||||
if (jsonObj.get("ArrayArrayNumber") != null && !jsonObj.get("ArrayArrayNumber").isJsonNull() && !jsonObj.get("ArrayArrayNumber").isJsonArray()) {
|
||||
throw new IllegalArgumentException(String.format("Expected the field `ArrayArrayNumber` to be an array in the JSON string but got `%s`", jsonObj.get("ArrayArrayNumber").toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ public class ArrayOfNumberOnly {
|
||||
}
|
||||
JsonObject jsonObj = jsonElement.getAsJsonObject();
|
||||
// ensure the optional json data is an array if present
|
||||
if (jsonObj.get("ArrayNumber") != null && !jsonObj.get("ArrayNumber").isJsonArray()) {
|
||||
if (jsonObj.get("ArrayNumber") != null && !jsonObj.get("ArrayNumber").isJsonNull() && !jsonObj.get("ArrayNumber").isJsonArray()) {
|
||||
throw new IllegalArgumentException(String.format("Expected the field `ArrayNumber` to be an array in the JSON string but got `%s`", jsonObj.get("ArrayNumber").toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,15 +236,15 @@ public class ArrayTest {
|
||||
}
|
||||
JsonObject jsonObj = jsonElement.getAsJsonObject();
|
||||
// ensure the optional json data is an array if present
|
||||
if (jsonObj.get("array_of_string") != null && !jsonObj.get("array_of_string").isJsonArray()) {
|
||||
if (jsonObj.get("array_of_string") != null && !jsonObj.get("array_of_string").isJsonNull() && !jsonObj.get("array_of_string").isJsonArray()) {
|
||||
throw new IllegalArgumentException(String.format("Expected the field `array_of_string` to be an array in the JSON string but got `%s`", jsonObj.get("array_of_string").toString()));
|
||||
}
|
||||
// ensure the optional json data is an array if present
|
||||
if (jsonObj.get("array_array_of_integer") != null && !jsonObj.get("array_array_of_integer").isJsonArray()) {
|
||||
if (jsonObj.get("array_array_of_integer") != null && !jsonObj.get("array_array_of_integer").isJsonNull() && !jsonObj.get("array_array_of_integer").isJsonArray()) {
|
||||
throw new IllegalArgumentException(String.format("Expected the field `array_array_of_integer` to be an array in the JSON string but got `%s`", jsonObj.get("array_array_of_integer").toString()));
|
||||
}
|
||||
// ensure the optional json data is an array if present
|
||||
if (jsonObj.get("array_array_of_model") != null && !jsonObj.get("array_array_of_model").isJsonArray()) {
|
||||
if (jsonObj.get("array_array_of_model") != null && !jsonObj.get("array_array_of_model").isJsonNull() && !jsonObj.get("array_array_of_model").isJsonArray()) {
|
||||
throw new IllegalArgumentException(String.format("Expected the field `array_array_of_model` to be an array in the JSON string but got `%s`", jsonObj.get("array_array_of_model").toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,7 +288,7 @@ public class EnumArrays {
|
||||
throw new IllegalArgumentException(String.format("Expected the field `just_symbol` to be a primitive type in the JSON string but got `%s`", jsonObj.get("just_symbol").toString()));
|
||||
}
|
||||
// ensure the optional json data is an array if present
|
||||
if (jsonObj.get("array_enum") != null && !jsonObj.get("array_enum").isJsonArray()) {
|
||||
if (jsonObj.get("array_enum") != null && !jsonObj.get("array_enum").isJsonNull() && !jsonObj.get("array_enum").isJsonArray()) {
|
||||
throw new IllegalArgumentException(String.format("Expected the field `array_enum` to be an array in the JSON string but got `%s`", jsonObj.get("array_enum").toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1015,51 +1015,51 @@ public class XmlItem {
|
||||
throw new IllegalArgumentException(String.format("Expected the field `attribute_string` to be a primitive type in the JSON string but got `%s`", jsonObj.get("attribute_string").toString()));
|
||||
}
|
||||
// ensure the optional json data is an array if present
|
||||
if (jsonObj.get("wrapped_array") != null && !jsonObj.get("wrapped_array").isJsonArray()) {
|
||||
if (jsonObj.get("wrapped_array") != null && !jsonObj.get("wrapped_array").isJsonNull() && !jsonObj.get("wrapped_array").isJsonArray()) {
|
||||
throw new IllegalArgumentException(String.format("Expected the field `wrapped_array` to be an array in the JSON string but got `%s`", jsonObj.get("wrapped_array").toString()));
|
||||
}
|
||||
if ((jsonObj.get("name_string") != null && !jsonObj.get("name_string").isJsonNull()) && !jsonObj.get("name_string").isJsonPrimitive()) {
|
||||
throw new IllegalArgumentException(String.format("Expected the field `name_string` to be a primitive type in the JSON string but got `%s`", jsonObj.get("name_string").toString()));
|
||||
}
|
||||
// ensure the optional json data is an array if present
|
||||
if (jsonObj.get("name_array") != null && !jsonObj.get("name_array").isJsonArray()) {
|
||||
if (jsonObj.get("name_array") != null && !jsonObj.get("name_array").isJsonNull() && !jsonObj.get("name_array").isJsonArray()) {
|
||||
throw new IllegalArgumentException(String.format("Expected the field `name_array` to be an array in the JSON string but got `%s`", jsonObj.get("name_array").toString()));
|
||||
}
|
||||
// ensure the optional json data is an array if present
|
||||
if (jsonObj.get("name_wrapped_array") != null && !jsonObj.get("name_wrapped_array").isJsonArray()) {
|
||||
if (jsonObj.get("name_wrapped_array") != null && !jsonObj.get("name_wrapped_array").isJsonNull() && !jsonObj.get("name_wrapped_array").isJsonArray()) {
|
||||
throw new IllegalArgumentException(String.format("Expected the field `name_wrapped_array` to be an array in the JSON string but got `%s`", jsonObj.get("name_wrapped_array").toString()));
|
||||
}
|
||||
if ((jsonObj.get("prefix_string") != null && !jsonObj.get("prefix_string").isJsonNull()) && !jsonObj.get("prefix_string").isJsonPrimitive()) {
|
||||
throw new IllegalArgumentException(String.format("Expected the field `prefix_string` to be a primitive type in the JSON string but got `%s`", jsonObj.get("prefix_string").toString()));
|
||||
}
|
||||
// ensure the optional json data is an array if present
|
||||
if (jsonObj.get("prefix_array") != null && !jsonObj.get("prefix_array").isJsonArray()) {
|
||||
if (jsonObj.get("prefix_array") != null && !jsonObj.get("prefix_array").isJsonNull() && !jsonObj.get("prefix_array").isJsonArray()) {
|
||||
throw new IllegalArgumentException(String.format("Expected the field `prefix_array` to be an array in the JSON string but got `%s`", jsonObj.get("prefix_array").toString()));
|
||||
}
|
||||
// ensure the optional json data is an array if present
|
||||
if (jsonObj.get("prefix_wrapped_array") != null && !jsonObj.get("prefix_wrapped_array").isJsonArray()) {
|
||||
if (jsonObj.get("prefix_wrapped_array") != null && !jsonObj.get("prefix_wrapped_array").isJsonNull() && !jsonObj.get("prefix_wrapped_array").isJsonArray()) {
|
||||
throw new IllegalArgumentException(String.format("Expected the field `prefix_wrapped_array` to be an array in the JSON string but got `%s`", jsonObj.get("prefix_wrapped_array").toString()));
|
||||
}
|
||||
if ((jsonObj.get("namespace_string") != null && !jsonObj.get("namespace_string").isJsonNull()) && !jsonObj.get("namespace_string").isJsonPrimitive()) {
|
||||
throw new IllegalArgumentException(String.format("Expected the field `namespace_string` to be a primitive type in the JSON string but got `%s`", jsonObj.get("namespace_string").toString()));
|
||||
}
|
||||
// ensure the optional json data is an array if present
|
||||
if (jsonObj.get("namespace_array") != null && !jsonObj.get("namespace_array").isJsonArray()) {
|
||||
if (jsonObj.get("namespace_array") != null && !jsonObj.get("namespace_array").isJsonNull() && !jsonObj.get("namespace_array").isJsonArray()) {
|
||||
throw new IllegalArgumentException(String.format("Expected the field `namespace_array` to be an array in the JSON string but got `%s`", jsonObj.get("namespace_array").toString()));
|
||||
}
|
||||
// ensure the optional json data is an array if present
|
||||
if (jsonObj.get("namespace_wrapped_array") != null && !jsonObj.get("namespace_wrapped_array").isJsonArray()) {
|
||||
if (jsonObj.get("namespace_wrapped_array") != null && !jsonObj.get("namespace_wrapped_array").isJsonNull() && !jsonObj.get("namespace_wrapped_array").isJsonArray()) {
|
||||
throw new IllegalArgumentException(String.format("Expected the field `namespace_wrapped_array` to be an array in the JSON string but got `%s`", jsonObj.get("namespace_wrapped_array").toString()));
|
||||
}
|
||||
if ((jsonObj.get("prefix_ns_string") != null && !jsonObj.get("prefix_ns_string").isJsonNull()) && !jsonObj.get("prefix_ns_string").isJsonPrimitive()) {
|
||||
throw new IllegalArgumentException(String.format("Expected the field `prefix_ns_string` to be a primitive type in the JSON string but got `%s`", jsonObj.get("prefix_ns_string").toString()));
|
||||
}
|
||||
// ensure the optional json data is an array if present
|
||||
if (jsonObj.get("prefix_ns_array") != null && !jsonObj.get("prefix_ns_array").isJsonArray()) {
|
||||
if (jsonObj.get("prefix_ns_array") != null && !jsonObj.get("prefix_ns_array").isJsonNull() && !jsonObj.get("prefix_ns_array").isJsonArray()) {
|
||||
throw new IllegalArgumentException(String.format("Expected the field `prefix_ns_array` to be an array in the JSON string but got `%s`", jsonObj.get("prefix_ns_array").toString()));
|
||||
}
|
||||
// ensure the optional json data is an array if present
|
||||
if (jsonObj.get("prefix_ns_wrapped_array") != null && !jsonObj.get("prefix_ns_wrapped_array").isJsonArray()) {
|
||||
if (jsonObj.get("prefix_ns_wrapped_array") != null && !jsonObj.get("prefix_ns_wrapped_array").isJsonNull() && !jsonObj.get("prefix_ns_wrapped_array").isJsonArray()) {
|
||||
throw new IllegalArgumentException(String.format("Expected the field `prefix_ns_wrapped_array` to be an array in the JSON string but got `%s`", jsonObj.get("prefix_ns_wrapped_array").toString()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user