|
| 1 | +/* |
| 2 | + * Regula Document Reader Web API |
| 3 | + * Documents recognition as easy as reading two bytes. # Clients: * [JavaScript](https://github.com/regulaforensics/DocumentReader-web-js-client) client for the browser and node.js based on axios * [Java](https://github.com/regulaforensics/DocumentReader-web-java-client) client compatible with jvm and android * [Python](https://github.com/regulaforensics/DocumentReader-web-python-client) 3.5+ client * [C#](https://github.com/regulaforensics/DocumentReader-web-csharp-client) client for .NET & .NET Core |
| 4 | + * |
| 5 | + * The version of the OpenAPI document: 7.4.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 | +package com.regula.documentreader.webclient.model; |
| 14 | + |
| 15 | +import com.google.gson.Gson; |
| 16 | +import com.google.gson.JsonElement; |
| 17 | +import com.google.gson.JsonObject; |
| 18 | +import com.google.gson.TypeAdapter; |
| 19 | +import com.google.gson.TypeAdapterFactory; |
| 20 | +import com.google.gson.annotations.SerializedName; |
| 21 | +import com.google.gson.reflect.TypeToken; |
| 22 | +import com.google.gson.stream.JsonReader; |
| 23 | +import com.google.gson.stream.JsonWriter; |
| 24 | +import com.regula.documentreader.webclient.JSON; |
| 25 | +import java.io.IOException; |
| 26 | +import java.util.HashSet; |
| 27 | +import java.util.Map; |
| 28 | +import java.util.Objects; |
| 29 | +import java.util.Set; |
| 30 | + |
| 31 | +/** DocVisualExtendedFieldRectItem */ |
| 32 | +@javax.annotation.Generated( |
| 33 | + value = "org.openapitools.codegen.languages.JavaClientCodegen", |
| 34 | + comments = "Generator version: 7.12.0") |
| 35 | +public class DocVisualExtendedFieldRectItem { |
| 36 | + public static final String SERIALIZED_NAME_FIELD_RECT = "FieldRect"; |
| 37 | + |
| 38 | + @SerializedName(SERIALIZED_NAME_FIELD_RECT) |
| 39 | + @javax.annotation.Nullable |
| 40 | + private RectangleCoordinates fieldRect; |
| 41 | + |
| 42 | + public DocVisualExtendedFieldRectItem() {} |
| 43 | + |
| 44 | + public DocVisualExtendedFieldRectItem fieldRect( |
| 45 | + @javax.annotation.Nullable RectangleCoordinates fieldRect) { |
| 46 | + this.fieldRect = fieldRect; |
| 47 | + return this; |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Get fieldRect |
| 52 | + * |
| 53 | + * @return fieldRect |
| 54 | + */ |
| 55 | + @javax.annotation.Nullable |
| 56 | + public RectangleCoordinates getFieldRect() { |
| 57 | + return fieldRect; |
| 58 | + } |
| 59 | + |
| 60 | + public void setFieldRect(@javax.annotation.Nullable RectangleCoordinates fieldRect) { |
| 61 | + this.fieldRect = fieldRect; |
| 62 | + } |
| 63 | + |
| 64 | + @Override |
| 65 | + public boolean equals(Object o) { |
| 66 | + if (this == o) { |
| 67 | + return true; |
| 68 | + } |
| 69 | + if (o == null || getClass() != o.getClass()) { |
| 70 | + return false; |
| 71 | + } |
| 72 | + DocVisualExtendedFieldRectItem docVisualExtendedFieldRectItem = |
| 73 | + (DocVisualExtendedFieldRectItem) o; |
| 74 | + return Objects.equals(this.fieldRect, docVisualExtendedFieldRectItem.fieldRect); |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + public int hashCode() { |
| 79 | + return Objects.hash(fieldRect); |
| 80 | + } |
| 81 | + |
| 82 | + @Override |
| 83 | + public String toString() { |
| 84 | + StringBuilder sb = new StringBuilder(); |
| 85 | + sb.append("class DocVisualExtendedFieldRectItem {\n"); |
| 86 | + sb.append(" fieldRect: ").append(toIndentedString(fieldRect)).append("\n"); |
| 87 | + sb.append("}"); |
| 88 | + return sb.toString(); |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Convert the given object to string with each line indented by 4 spaces (except the first line). |
| 93 | + */ |
| 94 | + private String toIndentedString(Object o) { |
| 95 | + if (o == null) { |
| 96 | + return "null"; |
| 97 | + } |
| 98 | + return o.toString().replace("\n", "\n "); |
| 99 | + } |
| 100 | + |
| 101 | + public static HashSet<String> openapiFields; |
| 102 | + public static HashSet<String> openapiRequiredFields; |
| 103 | + |
| 104 | + static { |
| 105 | + // a set of all properties/fields (JSON key names) |
| 106 | + openapiFields = new HashSet<String>(); |
| 107 | + openapiFields.add("FieldRect"); |
| 108 | + |
| 109 | + // a set of required properties/fields (JSON key names) |
| 110 | + openapiRequiredFields = new HashSet<String>(); |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * Validates the JSON Element and throws an exception if issues found |
| 115 | + * |
| 116 | + * @param jsonElement JSON Element |
| 117 | + * @throws IOException if the JSON Element is invalid with respect to |
| 118 | + * DocVisualExtendedFieldRectItem |
| 119 | + */ |
| 120 | + public static void validateJsonElement(JsonElement jsonElement) throws IOException { |
| 121 | + if (jsonElement == null) { |
| 122 | + if (!DocVisualExtendedFieldRectItem.openapiRequiredFields |
| 123 | + .isEmpty()) { // has required fields but JSON element is null |
| 124 | + throw new IllegalArgumentException( |
| 125 | + String.format( |
| 126 | + "The required field(s) %s in DocVisualExtendedFieldRectItem is not found in the empty JSON string", |
| 127 | + DocVisualExtendedFieldRectItem.openapiRequiredFields.toString())); |
| 128 | + } |
| 129 | + } |
| 130 | + |
| 131 | + Set<Map.Entry<String, JsonElement>> entries = jsonElement.getAsJsonObject().entrySet(); |
| 132 | + // check to see if the JSON string contains additional fields |
| 133 | + for (Map.Entry<String, JsonElement> entry : entries) { |
| 134 | + if (!DocVisualExtendedFieldRectItem.openapiFields.contains(entry.getKey())) { |
| 135 | + throw new IllegalArgumentException( |
| 136 | + String.format( |
| 137 | + "The field `%s` in the JSON string is not defined in the `DocVisualExtendedFieldRectItem` properties. JSON: %s", |
| 138 | + entry.getKey(), jsonElement.toString())); |
| 139 | + } |
| 140 | + } |
| 141 | + JsonObject jsonObj = jsonElement.getAsJsonObject(); |
| 142 | + // validate the optional field `FieldRect` |
| 143 | + if (jsonObj.get("FieldRect") != null && !jsonObj.get("FieldRect").isJsonNull()) { |
| 144 | + RectangleCoordinates.validateJsonElement(jsonObj.get("FieldRect")); |
| 145 | + } |
| 146 | + } |
| 147 | + |
| 148 | + public static class CustomTypeAdapterFactory implements TypeAdapterFactory { |
| 149 | + @SuppressWarnings("unchecked") |
| 150 | + @Override |
| 151 | + public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) { |
| 152 | + if (!DocVisualExtendedFieldRectItem.class.isAssignableFrom(type.getRawType())) { |
| 153 | + return null; // this class only serializes 'DocVisualExtendedFieldRectItem' and its subtypes |
| 154 | + } |
| 155 | + final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class); |
| 156 | + final TypeAdapter<DocVisualExtendedFieldRectItem> thisAdapter = |
| 157 | + gson.getDelegateAdapter(this, TypeToken.get(DocVisualExtendedFieldRectItem.class)); |
| 158 | + |
| 159 | + return (TypeAdapter<T>) |
| 160 | + new TypeAdapter<DocVisualExtendedFieldRectItem>() { |
| 161 | + @Override |
| 162 | + public void write(JsonWriter out, DocVisualExtendedFieldRectItem value) |
| 163 | + throws IOException { |
| 164 | + JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); |
| 165 | + elementAdapter.write(out, obj); |
| 166 | + } |
| 167 | + |
| 168 | + @Override |
| 169 | + public DocVisualExtendedFieldRectItem read(JsonReader in) throws IOException { |
| 170 | + JsonElement jsonElement = elementAdapter.read(in); |
| 171 | + validateJsonElement(jsonElement); |
| 172 | + return thisAdapter.fromJsonTree(jsonElement); |
| 173 | + } |
| 174 | + }.nullSafe(); |
| 175 | + } |
| 176 | + } |
| 177 | + |
| 178 | + /** |
| 179 | + * Create an instance of DocVisualExtendedFieldRectItem given an JSON string |
| 180 | + * |
| 181 | + * @param jsonString JSON string |
| 182 | + * @return An instance of DocVisualExtendedFieldRectItem |
| 183 | + * @throws IOException if the JSON string is invalid with respect to |
| 184 | + * DocVisualExtendedFieldRectItem |
| 185 | + */ |
| 186 | + public static DocVisualExtendedFieldRectItem fromJson(String jsonString) throws IOException { |
| 187 | + return JSON.getGson().fromJson(jsonString, DocVisualExtendedFieldRectItem.class); |
| 188 | + } |
| 189 | + |
| 190 | + /** |
| 191 | + * Convert an instance of DocVisualExtendedFieldRectItem to an JSON string |
| 192 | + * |
| 193 | + * @return JSON string |
| 194 | + */ |
| 195 | + public String toJson() { |
| 196 | + return JSON.getGson().toJson(this); |
| 197 | + } |
| 198 | +} |
0 commit comments