|
| 1 | +/* |
| 2 | + * OpenAPI Petstore |
| 3 | + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ |
| 4 | + * |
| 5 | + * The version of the OpenAPI document: 1.0.0 |
| 6 | + * |
| 7 | + * |
| 8 | + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). |
| 9 | + * https://openapi-generator.tech |
| 10 | + * Do not edit the class manually. |
| 11 | + */ |
| 12 | + |
| 13 | + |
| 14 | +package org.openapitools.client.model; |
| 15 | + |
| 16 | +import java.util.Objects; |
| 17 | +import com.google.gson.TypeAdapter; |
| 18 | +import com.google.gson.annotations.JsonAdapter; |
| 19 | +import com.google.gson.annotations.SerializedName; |
| 20 | +import com.google.gson.stream.JsonReader; |
| 21 | +import com.google.gson.stream.JsonWriter; |
| 22 | +import java.io.IOException; |
| 23 | +import java.util.ArrayList; |
| 24 | +import java.util.Arrays; |
| 25 | +import java.util.List; |
| 26 | + |
| 27 | +import com.google.gson.Gson; |
| 28 | +import com.google.gson.GsonBuilder; |
| 29 | +import com.google.gson.JsonArray; |
| 30 | +import com.google.gson.JsonDeserializationContext; |
| 31 | +import com.google.gson.JsonDeserializer; |
| 32 | +import com.google.gson.JsonElement; |
| 33 | +import com.google.gson.JsonObject; |
| 34 | +import com.google.gson.JsonParseException; |
| 35 | +import com.google.gson.TypeAdapterFactory; |
| 36 | +import com.google.gson.reflect.TypeToken; |
| 37 | +import com.google.gson.TypeAdapter; |
| 38 | +import com.google.gson.stream.JsonReader; |
| 39 | +import com.google.gson.stream.JsonWriter; |
| 40 | +import java.io.IOException; |
| 41 | + |
| 42 | +import java.util.HashMap; |
| 43 | +import java.util.HashSet; |
| 44 | +import java.util.List; |
| 45 | +import java.util.Map; |
| 46 | +import java.util.Set; |
| 47 | + |
| 48 | +import org.openapitools.client.JSON; |
| 49 | + |
| 50 | +/** |
| 51 | + * NestedArrayWithDefaultValues |
| 52 | + */ |
| 53 | +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.15.0-SNAPSHOT") |
| 54 | +public class NestedArrayWithDefaultValues { |
| 55 | + public static final String SERIALIZED_NAME_NESTED_ARRAY = "nestedArray"; |
| 56 | + @SerializedName(SERIALIZED_NAME_NESTED_ARRAY) |
| 57 | + @javax.annotation.Nullable |
| 58 | + private List<List<String>> nestedArray; |
| 59 | + |
| 60 | + public NestedArrayWithDefaultValues() { |
| 61 | + } |
| 62 | + |
| 63 | + public NestedArrayWithDefaultValues nestedArray(@javax.annotation.Nullable List<List<String>> nestedArray) { |
| 64 | + this.nestedArray = nestedArray; |
| 65 | + return this; |
| 66 | + } |
| 67 | + |
| 68 | + public NestedArrayWithDefaultValues addNestedArrayItem(List<String> nestedArrayItem) { |
| 69 | + if (this.nestedArray == null) { |
| 70 | + this.nestedArray = new ArrayList<>(); |
| 71 | + } |
| 72 | + this.nestedArray.add(nestedArrayItem); |
| 73 | + return this; |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * Get nestedArray |
| 78 | + * @return nestedArray |
| 79 | + */ |
| 80 | + @javax.annotation.Nullable |
| 81 | + public List<List<String>> getNestedArray() { |
| 82 | + return nestedArray; |
| 83 | + } |
| 84 | + |
| 85 | + public void setNestedArray(@javax.annotation.Nullable List<List<String>> nestedArray) { |
| 86 | + this.nestedArray = nestedArray; |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * A container for additional, undeclared properties. |
| 91 | + * This is a holder for any undeclared properties as specified with |
| 92 | + * the 'additionalProperties' keyword in the OAS document. |
| 93 | + */ |
| 94 | + private Map<String, Object> additionalProperties; |
| 95 | + |
| 96 | + /** |
| 97 | + * Set the additional (undeclared) property with the specified name and value. |
| 98 | + * If the property does not already exist, create it otherwise replace it. |
| 99 | + * |
| 100 | + * @param key name of the property |
| 101 | + * @param value value of the property |
| 102 | + * @return the NestedArrayWithDefaultValues instance itself |
| 103 | + */ |
| 104 | + public NestedArrayWithDefaultValues putAdditionalProperty(String key, Object value) { |
| 105 | + if (this.additionalProperties == null) { |
| 106 | + this.additionalProperties = new HashMap<String, Object>(); |
| 107 | + } |
| 108 | + this.additionalProperties.put(key, value); |
| 109 | + return this; |
| 110 | + } |
| 111 | + |
| 112 | + /** |
| 113 | + * Return the additional (undeclared) property. |
| 114 | + * |
| 115 | + * @return a map of objects |
| 116 | + */ |
| 117 | + public Map<String, Object> getAdditionalProperties() { |
| 118 | + return additionalProperties; |
| 119 | + } |
| 120 | + |
| 121 | + /** |
| 122 | + * Return the additional (undeclared) property with the specified name. |
| 123 | + * |
| 124 | + * @param key name of the property |
| 125 | + * @return an object |
| 126 | + */ |
| 127 | + public Object getAdditionalProperty(String key) { |
| 128 | + if (this.additionalProperties == null) { |
| 129 | + return null; |
| 130 | + } |
| 131 | + return this.additionalProperties.get(key); |
| 132 | + } |
| 133 | + |
| 134 | + |
| 135 | + @Override |
| 136 | + public boolean equals(Object o) { |
| 137 | + if (this == o) { |
| 138 | + return true; |
| 139 | + } |
| 140 | + if (o == null || getClass() != o.getClass()) { |
| 141 | + return false; |
| 142 | + } |
| 143 | + NestedArrayWithDefaultValues nestedArrayWithDefaultValues = (NestedArrayWithDefaultValues) o; |
| 144 | + return Objects.equals(this.nestedArray, nestedArrayWithDefaultValues.nestedArray)&& |
| 145 | + Objects.equals(this.additionalProperties, nestedArrayWithDefaultValues.additionalProperties); |
| 146 | + } |
| 147 | + |
| 148 | + @Override |
| 149 | + public int hashCode() { |
| 150 | + return Objects.hash(nestedArray, additionalProperties); |
| 151 | + } |
| 152 | + |
| 153 | + @Override |
| 154 | + public String toString() { |
| 155 | + StringBuilder sb = new StringBuilder(); |
| 156 | + sb.append("class NestedArrayWithDefaultValues {\n"); |
| 157 | + sb.append(" nestedArray: ").append(toIndentedString(nestedArray)).append("\n"); |
| 158 | + sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n"); |
| 159 | + sb.append("}"); |
| 160 | + return sb.toString(); |
| 161 | + } |
| 162 | + |
| 163 | + /** |
| 164 | + * Convert the given object to string with each line indented by 4 spaces |
| 165 | + * (except the first line). |
| 166 | + */ |
| 167 | + private String toIndentedString(Object o) { |
| 168 | + if (o == null) { |
| 169 | + return "null"; |
| 170 | + } |
| 171 | + return o.toString().replace("\n", "\n "); |
| 172 | + } |
| 173 | + |
| 174 | + |
| 175 | + public static HashSet<String> openapiFields; |
| 176 | + public static HashSet<String> openapiRequiredFields; |
| 177 | + |
| 178 | + static { |
| 179 | + // a set of all properties/fields (JSON key names) |
| 180 | + openapiFields = new HashSet<String>(Arrays.asList("nestedArray")); |
| 181 | + |
| 182 | + // a set of required properties/fields (JSON key names) |
| 183 | + openapiRequiredFields = new HashSet<String>(0); |
| 184 | + } |
| 185 | + |
| 186 | + /** |
| 187 | + * Validates the JSON Element and throws an exception if issues found |
| 188 | + * |
| 189 | + * @param jsonElement JSON Element |
| 190 | + * @throws IOException if the JSON Element is invalid with respect to NestedArrayWithDefaultValues |
| 191 | + */ |
| 192 | + public static void validateJsonElement(JsonElement jsonElement) throws IOException { |
| 193 | + if (jsonElement == null) { |
| 194 | + if (!NestedArrayWithDefaultValues.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null |
| 195 | + throw new IllegalArgumentException(String.format("The required field(s) %s in NestedArrayWithDefaultValues is not found in the empty JSON string", NestedArrayWithDefaultValues.openapiRequiredFields.toString())); |
| 196 | + } |
| 197 | + } |
| 198 | + JsonObject jsonObj = jsonElement.getAsJsonObject(); |
| 199 | + // ensure the optional json data is an array if present |
| 200 | + if (jsonObj.get("nestedArray") != null && !jsonObj.get("nestedArray").isJsonNull() && !jsonObj.get("nestedArray").isJsonArray()) { |
| 201 | + throw new IllegalArgumentException(String.format("Expected the field `nestedArray` to be an array in the JSON string but got `%s`", jsonObj.get("nestedArray").toString())); |
| 202 | + } |
| 203 | + } |
| 204 | + |
| 205 | + public static class CustomTypeAdapterFactory implements TypeAdapterFactory { |
| 206 | + @SuppressWarnings("unchecked") |
| 207 | + @Override |
| 208 | + public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) { |
| 209 | + if (!NestedArrayWithDefaultValues.class.isAssignableFrom(type.getRawType())) { |
| 210 | + return null; // this class only serializes 'NestedArrayWithDefaultValues' and its subtypes |
| 211 | + } |
| 212 | + final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class); |
| 213 | + final TypeAdapter<NestedArrayWithDefaultValues> thisAdapter |
| 214 | + = gson.getDelegateAdapter(this, TypeToken.get(NestedArrayWithDefaultValues.class)); |
| 215 | + |
| 216 | + return (TypeAdapter<T>) new TypeAdapter<NestedArrayWithDefaultValues>() { |
| 217 | + @Override |
| 218 | + public void write(JsonWriter out, NestedArrayWithDefaultValues value) throws IOException { |
| 219 | + JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); |
| 220 | + obj.remove("additionalProperties"); |
| 221 | + // serialize additional properties |
| 222 | + if (value.getAdditionalProperties() != null) { |
| 223 | + for (Map.Entry<String, Object> entry : value.getAdditionalProperties().entrySet()) { |
| 224 | + if (entry.getValue() instanceof String) |
| 225 | + obj.addProperty(entry.getKey(), (String) entry.getValue()); |
| 226 | + else if (entry.getValue() instanceof Number) |
| 227 | + obj.addProperty(entry.getKey(), (Number) entry.getValue()); |
| 228 | + else if (entry.getValue() instanceof Boolean) |
| 229 | + obj.addProperty(entry.getKey(), (Boolean) entry.getValue()); |
| 230 | + else if (entry.getValue() instanceof Character) |
| 231 | + obj.addProperty(entry.getKey(), (Character) entry.getValue()); |
| 232 | + else { |
| 233 | + JsonElement jsonElement = gson.toJsonTree(entry.getValue()); |
| 234 | + if (jsonElement.isJsonArray()) { |
| 235 | + obj.add(entry.getKey(), jsonElement.getAsJsonArray()); |
| 236 | + } else { |
| 237 | + obj.add(entry.getKey(), jsonElement.getAsJsonObject()); |
| 238 | + } |
| 239 | + } |
| 240 | + } |
| 241 | + } |
| 242 | + elementAdapter.write(out, obj); |
| 243 | + } |
| 244 | + |
| 245 | + @Override |
| 246 | + public NestedArrayWithDefaultValues read(JsonReader in) throws IOException { |
| 247 | + JsonElement jsonElement = elementAdapter.read(in); |
| 248 | + validateJsonElement(jsonElement); |
| 249 | + JsonObject jsonObj = jsonElement.getAsJsonObject(); |
| 250 | + // store additional fields in the deserialized instance |
| 251 | + NestedArrayWithDefaultValues instance = thisAdapter.fromJsonTree(jsonObj); |
| 252 | + for (Map.Entry<String, JsonElement> entry : jsonObj.entrySet()) { |
| 253 | + if (!openapiFields.contains(entry.getKey())) { |
| 254 | + if (entry.getValue().isJsonPrimitive()) { // primitive type |
| 255 | + if (entry.getValue().getAsJsonPrimitive().isString()) |
| 256 | + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsString()); |
| 257 | + else if (entry.getValue().getAsJsonPrimitive().isNumber()) |
| 258 | + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsNumber()); |
| 259 | + else if (entry.getValue().getAsJsonPrimitive().isBoolean()) |
| 260 | + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsBoolean()); |
| 261 | + else |
| 262 | + throw new IllegalArgumentException(String.format("The field `%s` has unknown primitive type. Value: %s", entry.getKey(), entry.getValue().toString())); |
| 263 | + } else if (entry.getValue().isJsonArray()) { |
| 264 | + instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), List.class)); |
| 265 | + } else { // JSON object |
| 266 | + instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), HashMap.class)); |
| 267 | + } |
| 268 | + } |
| 269 | + } |
| 270 | + return instance; |
| 271 | + } |
| 272 | + |
| 273 | + }.nullSafe(); |
| 274 | + } |
| 275 | + } |
| 276 | + |
| 277 | + /** |
| 278 | + * Create an instance of NestedArrayWithDefaultValues given an JSON string |
| 279 | + * |
| 280 | + * @param jsonString JSON string |
| 281 | + * @return An instance of NestedArrayWithDefaultValues |
| 282 | + * @throws IOException if the JSON string is invalid with respect to NestedArrayWithDefaultValues |
| 283 | + */ |
| 284 | + public static NestedArrayWithDefaultValues fromJson(String jsonString) throws IOException { |
| 285 | + return JSON.getGson().fromJson(jsonString, NestedArrayWithDefaultValues.class); |
| 286 | + } |
| 287 | + |
| 288 | + /** |
| 289 | + * Convert an instance of NestedArrayWithDefaultValues to an JSON string |
| 290 | + * |
| 291 | + * @return JSON string |
| 292 | + */ |
| 293 | + public String toJson() { |
| 294 | + return JSON.getGson().toJson(this); |
| 295 | + } |
| 296 | +} |
| 297 | + |
0 commit comments