[JAVA] fix ClassCastException validating an optional JsonArray which is a JsonNullable (#13448)

This commit is contained in:
ehealthexperts-rk
2022-09-17 16:37:09 +02:00
committed by GitHub
parent 517816d72b
commit 62d29c3be3
11 changed files with 133 additions and 110 deletions

View File

@@ -420,17 +420,19 @@ public class Pet {
if ((jsonObj.get("photoUrls") != null && !jsonObj.get("photoUrls").isJsonNull()) && !jsonObj.get("photoUrls").isJsonArray()) {
throw new IllegalArgumentException(String.format("Expected the field `photoUrls` to be an array in the JSON string but got `%s`", jsonObj.get("photoUrls").toString()));
}
JsonArray jsonArraytags = jsonObj.getAsJsonArray("tags");
if (jsonArraytags != null) {
// ensure the json data is an array
if (!jsonObj.get("tags").isJsonArray()) {
throw new IllegalArgumentException(String.format("Expected the field `tags` to be an array in the JSON string but got `%s`", jsonObj.get("tags").toString()));
}
if (jsonObj.get("tags") != null && !jsonObj.get("tags").isJsonNull()) {
JsonArray jsonArraytags = jsonObj.getAsJsonArray("tags");
if (jsonArraytags != null) {
// ensure the json data is an array
if (!jsonObj.get("tags").isJsonArray()) {
throw new IllegalArgumentException(String.format("Expected the field `tags` to be an array in the JSON string but got `%s`", jsonObj.get("tags").toString()));
}
// validate the optional field `tags` (array)
for (int i = 0; i < jsonArraytags.size(); i++) {
Tag.validateJsonObject(jsonArraytags.get(i).getAsJsonObject());
};
// validate the optional field `tags` (array)
for (int i = 0; i < jsonArraytags.size(); i++) {
Tag.validateJsonObject(jsonArraytags.get(i).getAsJsonObject());
};
}
}
if ((jsonObj.get("status") != null && !jsonObj.get("status").isJsonNull()) && !jsonObj.get("status").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `status` to be a primitive type in the JSON string but got `%s`", jsonObj.get("status").toString()));