diff --git a/client/.openapi-generator/FILES b/client/.openapi-generator/FILES index 25acae2..32767ef 100755 --- a/client/.openapi-generator/FILES +++ b/client/.openapi-generator/FILES @@ -135,6 +135,8 @@ src/main/generated/com/regula/documentreader/webclient/model/LivenessParams.java src/main/generated/com/regula/documentreader/webclient/model/LogLevel.java src/main/generated/com/regula/documentreader/webclient/model/MDLDeviceEngagement.java src/main/generated/com/regula/documentreader/webclient/model/MDLDeviceRetrieval.java +src/main/generated/com/regula/documentreader/webclient/model/MDLItem.java +src/main/generated/com/regula/documentreader/webclient/model/MDLResult.java src/main/generated/com/regula/documentreader/webclient/model/MDLServerRetrieval.java src/main/generated/com/regula/documentreader/webclient/model/MRZDetectorResult.java src/main/generated/com/regula/documentreader/webclient/model/MRZFormat.java diff --git a/client/src/main/generated/com/regula/documentreader/webclient/JSON.java b/client/src/main/generated/com/regula/documentreader/webclient/JSON.java index 02dd7b3..5979156 100755 --- a/client/src/main/generated/com/regula/documentreader/webclient/JSON.java +++ b/client/src/main/generated/com/regula/documentreader/webclient/JSON.java @@ -331,6 +331,8 @@ public static GsonBuilder createGson() { com.regula.documentreader.webclient.model.RFIDGraphicsInfoResult.class); classByDiscriminatorValue.put( "109", com.regula.documentreader.webclient.model.ByteArrayResult.class); + classByDiscriminatorValue.put( + "121", com.regula.documentreader.webclient.model.MDLResult.class); classByDiscriminatorValue.put( "124", com.regula.documentreader.webclient.model.VDSNCDataResult.class); classByDiscriminatorValue.put( @@ -630,6 +632,20 @@ public static GsonBuilder createGson() { getDiscriminatorValue(readElement, "result_type")); } }) + .registerTypeSelector( + com.regula.documentreader.webclient.model.MDLResult.class, + new TypeSelector() { + @Override + public Class + getClassForElement(JsonElement readElement) { + Map classByDiscriminatorValue = new HashMap(); + classByDiscriminatorValue.put( + "MDLResult", com.regula.documentreader.webclient.model.MDLResult.class); + return getClassByDiscriminator( + classByDiscriminatorValue, + getDiscriminatorValue(readElement, "result_type")); + } + }) .registerTypeSelector( com.regula.documentreader.webclient.model.MRZDetectorResult.class, new TypeSelector() { @@ -766,6 +782,8 @@ public static GsonBuilder createGson() { com.regula.documentreader.webclient.model.RFIDGraphicsInfoResult.class); classByDiscriminatorValue.put( "109", com.regula.documentreader.webclient.model.ByteArrayResult.class); + classByDiscriminatorValue.put( + "121", com.regula.documentreader.webclient.model.MDLResult.class); classByDiscriminatorValue.put( "124", com.regula.documentreader.webclient.model.VDSNCDataResult.class); classByDiscriminatorValue.put( @@ -1204,6 +1222,10 @@ private static Class getClassByDiscriminator( .CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory( new com.regula.documentreader.webclient.model.LivenessParams.CustomTypeAdapterFactory()); + gsonBuilder.registerTypeAdapterFactory( + new com.regula.documentreader.webclient.model.MDLItem.CustomTypeAdapterFactory()); + gsonBuilder.registerTypeAdapterFactory( + new com.regula.documentreader.webclient.model.MDLResult.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory( new com.regula.documentreader.webclient.model.MRZDetectorResult.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory( diff --git a/client/src/main/generated/com/regula/documentreader/webclient/model/ContainerListListInner.java b/client/src/main/generated/com/regula/documentreader/webclient/model/ContainerListListInner.java index 5fe9008..59a3ed6 100644 --- a/client/src/main/generated/com/regula/documentreader/webclient/model/ContainerListListInner.java +++ b/client/src/main/generated/com/regula/documentreader/webclient/model/ContainerListListInner.java @@ -93,6 +93,8 @@ public TypeAdapter create(Gson gson, TypeToken type) { gson.getDelegateAdapter(this, TypeToken.get(VDSNCDataResult.class)); final TypeAdapter adapterVDSDataResult = gson.getDelegateAdapter(this, TypeToken.get(VDSDataResult.class)); + final TypeAdapter adapterMDLResult = + gson.getDelegateAdapter(this, TypeToken.get(MDLResult.class)); return (TypeAdapter) new TypeAdapter() { @@ -301,8 +303,15 @@ public void write(JsonWriter out, ContainerListListInner value) throws IOExcepti elementAdapter.write(out, element); return; } + // check if the actual instance is of the type `MDLResult` + if (value.getActualInstance() instanceof MDLResult) { + JsonElement element = + adapterMDLResult.toJsonTree((MDLResult) value.getActualInstance()); + elementAdapter.write(out, element); + return; + } throw new IOException( - "Failed to serialize as the type doesn't match oneOf schemas: AuthenticityResult, BarcodePositionResult, ByteArrayResult, ChosenDocumentTypeResult, DocBarCodeInfo, DocumentBinaryInfoResult, DocumentImageResult, DocumentPositionResult, DocumentTypesCandidatesResult, EncryptedRCLResult, FaceDetectionResult, GraphicsResult, ImageQualityResult, ImagesResult, LexicalAnalysisResult, LicenseResult, MRZDetectorResult, MRZPositionResult, MRZTestQualityResult, RFIDGraphicsInfoResult, RFIDTextDataResult, StatusResult, TextDataResult, TextResult, VDSDataResult, VDSNCDataResult"); + "Failed to serialize as the type doesn't match oneOf schemas: AuthenticityResult, BarcodePositionResult, ByteArrayResult, ChosenDocumentTypeResult, DocBarCodeInfo, DocumentBinaryInfoResult, DocumentImageResult, DocumentPositionResult, DocumentTypesCandidatesResult, EncryptedRCLResult, FaceDetectionResult, GraphicsResult, ImageQualityResult, ImagesResult, LexicalAnalysisResult, LicenseResult, MDLResult, MRZDetectorResult, MRZPositionResult, MRZTestQualityResult, RFIDGraphicsInfoResult, RFIDTextDataResult, StatusResult, TextDataResult, TextResult, VDSDataResult, VDSNCDataResult"); } @Override @@ -699,6 +708,20 @@ public ContainerListListInner read(JsonReader in) throws IOException { "Deserialization for VDSDataResult failed with `%s`.", e.getMessage())); log.log(Level.FINER, "Input data does not match schema 'VDSDataResult'", e); } + // deserialize MDLResult + try { + // validate the JSON object to see if any exception is thrown + MDLResult.validateJsonElement(jsonElement); + actualAdapter = adapterMDLResult; + match++; + log.log(Level.FINER, "Input data matches schema 'MDLResult'"); + } catch (Exception e) { + // deserialization failed, continue + errorMessages.add( + String.format( + "Deserialization for MDLResult failed with `%s`.", e.getMessage())); + log.log(Level.FINER, "Input data does not match schema 'MDLResult'", e); + } if (match == 1) { ContainerListListInner ret = new ContainerListListInner(); @@ -754,6 +777,7 @@ public ContainerListListInner(Object o) { schemas.put("RFIDTextDataResult", RFIDTextDataResult.class); schemas.put("VDSNCDataResult", VDSNCDataResult.class); schemas.put("VDSDataResult", VDSDataResult.class); + schemas.put("MDLResult", MDLResult.class); } @Override @@ -767,7 +791,7 @@ public Map> getSchemas() { * ChosenDocumentTypeResult, DocBarCodeInfo, DocumentBinaryInfoResult, DocumentImageResult, * DocumentPositionResult, DocumentTypesCandidatesResult, EncryptedRCLResult, FaceDetectionResult, * GraphicsResult, ImageQualityResult, ImagesResult, LexicalAnalysisResult, LicenseResult, - * MRZDetectorResult, MRZPositionResult, MRZTestQualityResult, RFIDGraphicsInfoResult, + * MDLResult, MRZDetectorResult, MRZPositionResult, MRZTestQualityResult, RFIDGraphicsInfoResult, * RFIDTextDataResult, StatusResult, TextDataResult, TextResult, VDSDataResult, VDSNCDataResult * *

It could be an instance of the 'oneOf' schemas. @@ -904,8 +928,13 @@ public void setActualInstance(Object instance) { return; } + if (instance instanceof MDLResult) { + super.setActualInstance(instance); + return; + } + throw new RuntimeException( - "Invalid instance type. Must be AuthenticityResult, BarcodePositionResult, ByteArrayResult, ChosenDocumentTypeResult, DocBarCodeInfo, DocumentBinaryInfoResult, DocumentImageResult, DocumentPositionResult, DocumentTypesCandidatesResult, EncryptedRCLResult, FaceDetectionResult, GraphicsResult, ImageQualityResult, ImagesResult, LexicalAnalysisResult, LicenseResult, MRZDetectorResult, MRZPositionResult, MRZTestQualityResult, RFIDGraphicsInfoResult, RFIDTextDataResult, StatusResult, TextDataResult, TextResult, VDSDataResult, VDSNCDataResult"); + "Invalid instance type. Must be AuthenticityResult, BarcodePositionResult, ByteArrayResult, ChosenDocumentTypeResult, DocBarCodeInfo, DocumentBinaryInfoResult, DocumentImageResult, DocumentPositionResult, DocumentTypesCandidatesResult, EncryptedRCLResult, FaceDetectionResult, GraphicsResult, ImageQualityResult, ImagesResult, LexicalAnalysisResult, LicenseResult, MDLResult, MRZDetectorResult, MRZPositionResult, MRZTestQualityResult, RFIDGraphicsInfoResult, RFIDTextDataResult, StatusResult, TextDataResult, TextResult, VDSDataResult, VDSNCDataResult"); } /** @@ -913,7 +942,7 @@ public void setActualInstance(Object instance) { * ByteArrayResult, ChosenDocumentTypeResult, DocBarCodeInfo, DocumentBinaryInfoResult, * DocumentImageResult, DocumentPositionResult, DocumentTypesCandidatesResult, EncryptedRCLResult, * FaceDetectionResult, GraphicsResult, ImageQualityResult, ImagesResult, LexicalAnalysisResult, - * LicenseResult, MRZDetectorResult, MRZPositionResult, MRZTestQualityResult, + * LicenseResult, MDLResult, MRZDetectorResult, MRZPositionResult, MRZTestQualityResult, * RFIDGraphicsInfoResult, RFIDTextDataResult, StatusResult, TextDataResult, TextResult, * VDSDataResult, VDSNCDataResult * @@ -921,7 +950,7 @@ public void setActualInstance(Object instance) { * ChosenDocumentTypeResult, DocBarCodeInfo, DocumentBinaryInfoResult, DocumentImageResult, * DocumentPositionResult, DocumentTypesCandidatesResult, EncryptedRCLResult, * FaceDetectionResult, GraphicsResult, ImageQualityResult, ImagesResult, - * LexicalAnalysisResult, LicenseResult, MRZDetectorResult, MRZPositionResult, + * LexicalAnalysisResult, LicenseResult, MDLResult, MRZDetectorResult, MRZPositionResult, * MRZTestQualityResult, RFIDGraphicsInfoResult, RFIDTextDataResult, StatusResult, * TextDataResult, TextResult, VDSDataResult, VDSNCDataResult) */ @@ -1218,6 +1247,17 @@ public VDSDataResult getVDSDataResult() throws ClassCastException { return (VDSDataResult) super.getActualInstance(); } + /** + * Get the actual instance of `MDLResult`. If the actual instance is not `MDLResult`, the + * ClassCastException will be thrown. + * + * @return The actual instance of `MDLResult` + * @throws ClassCastException if the instance is not `MDLResult` + */ + public MDLResult getMDLResult() throws ClassCastException { + return (MDLResult) super.getActualInstance(); + } + /** * Validates the JSON Element and throws an exception if issues found * @@ -1477,10 +1517,19 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti String.format("Deserialization for VDSDataResult failed with `%s`.", e.getMessage())); // continue to the next one } + // validate the json string with MDLResult + try { + MDLResult.validateJsonElement(jsonElement); + validCount++; + } catch (Exception e) { + errorMessages.add( + String.format("Deserialization for MDLResult failed with `%s`.", e.getMessage())); + // continue to the next one + } if (validCount != 1) { throw new IOException( String.format( - "The JSON string is invalid for ContainerListListInner with oneOf schemas: AuthenticityResult, BarcodePositionResult, ByteArrayResult, ChosenDocumentTypeResult, DocBarCodeInfo, DocumentBinaryInfoResult, DocumentImageResult, DocumentPositionResult, DocumentTypesCandidatesResult, EncryptedRCLResult, FaceDetectionResult, GraphicsResult, ImageQualityResult, ImagesResult, LexicalAnalysisResult, LicenseResult, MRZDetectorResult, MRZPositionResult, MRZTestQualityResult, RFIDGraphicsInfoResult, RFIDTextDataResult, StatusResult, TextDataResult, TextResult, VDSDataResult, VDSNCDataResult. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", + "The JSON string is invalid for ContainerListListInner with oneOf schemas: AuthenticityResult, BarcodePositionResult, ByteArrayResult, ChosenDocumentTypeResult, DocBarCodeInfo, DocumentBinaryInfoResult, DocumentImageResult, DocumentPositionResult, DocumentTypesCandidatesResult, EncryptedRCLResult, FaceDetectionResult, GraphicsResult, ImageQualityResult, ImagesResult, LexicalAnalysisResult, LicenseResult, MDLResult, MRZDetectorResult, MRZPositionResult, MRZTestQualityResult, RFIDGraphicsInfoResult, RFIDTextDataResult, StatusResult, TextDataResult, TextResult, VDSDataResult, VDSNCDataResult. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString())); } } diff --git a/client/src/main/generated/com/regula/documentreader/webclient/model/MDLItem.java b/client/src/main/generated/com/regula/documentreader/webclient/model/MDLItem.java new file mode 100644 index 0000000..a54adbb --- /dev/null +++ b/client/src/main/generated/com/regula/documentreader/webclient/model/MDLItem.java @@ -0,0 +1,198 @@ +/* + * Regula Document Reader Web API + * 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 + * + * The version of the OpenAPI document: 8.1.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.regula.documentreader.webclient.model; + +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.TypeAdapter; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.annotations.SerializedName; +import com.google.gson.reflect.TypeToken; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import com.regula.documentreader.webclient.JSON; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Objects; + +/** MDLItem */ +@javax.annotation.Generated( + value = "org.openapitools.codegen.languages.JavaClientCodegen", + comments = "Generator version: 7.15.0") +public class MDLItem { + public static final String SERIALIZED_NAME_MD_L_PARSED_RESPONSE = "MDLParsedResponse"; + + @SerializedName(SERIALIZED_NAME_MD_L_PARSED_RESPONSE) + @javax.annotation.Nonnull + private Map mdLParsedResponse; + + public MDLItem() {} + + public MDLItem mdLParsedResponse( + @javax.annotation.Nonnull Map mdLParsedResponse) { + this.mdLParsedResponse = mdLParsedResponse; + return this; + } + + public MDLItem putMdLParsedResponseItem(String key, Object mdLParsedResponseItem) { + if (this.mdLParsedResponse == null) { + this.mdLParsedResponse = new HashMap<>(); + } + this.mdLParsedResponse.put(key, mdLParsedResponseItem); + return this; + } + + /** + * Get mdLParsedResponse + * + * @return mdLParsedResponse + */ + @javax.annotation.Nonnull + public Map getMdLParsedResponse() { + return mdLParsedResponse; + } + + public void setMdLParsedResponse( + @javax.annotation.Nonnull Map mdLParsedResponse) { + this.mdLParsedResponse = mdLParsedResponse; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + MDLItem mdLItem = (MDLItem) o; + return Objects.equals(this.mdLParsedResponse, mdLItem.mdLParsedResponse); + } + + @Override + public int hashCode() { + return Objects.hash(mdLParsedResponse); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class MDLItem {\n"); + sb.append(" mdLParsedResponse: ").append(toIndentedString(mdLParsedResponse)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + public static HashSet openapiFields; + public static HashSet openapiRequiredFields; + + static { + // a set of all properties/fields (JSON key names) + openapiFields = new HashSet(Arrays.asList("MDLParsedResponse")); + + // a set of required properties/fields (JSON key names) + openapiRequiredFields = new HashSet(Arrays.asList("MDLParsedResponse")); + } + + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to MDLItem + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + if (jsonElement == null) { + if (!MDLItem.openapiRequiredFields + .isEmpty()) { // has required fields but JSON element is null + System.err.println( + String.format( + "The required field(s) %s in MDLItem is not found in the empty JSON string", + MDLItem.openapiRequiredFields.toString())); + } + } + + // check to make sure all required properties/fields are present in the JSON string + for (String requiredField : MDLItem.openapiRequiredFields) { + if (jsonElement.getAsJsonObject().get(requiredField) == null) { + System.err.println( + String.format( + "The required field `%s` is not found in the JSON string: %s", + requiredField, jsonElement.toString())); + } + } + JsonObject jsonObj = jsonElement.getAsJsonObject(); + } + + public static class CustomTypeAdapterFactory implements TypeAdapterFactory { + @SuppressWarnings("unchecked") + @Override + public TypeAdapter create(Gson gson, TypeToken type) { + if (!MDLItem.class.isAssignableFrom(type.getRawType())) { + return null; // this class only serializes 'MDLItem' and its subtypes + } + final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); + final TypeAdapter thisAdapter = + gson.getDelegateAdapter(this, TypeToken.get(MDLItem.class)); + + return (TypeAdapter) + new TypeAdapter() { + @Override + public void write(JsonWriter out, MDLItem value) throws IOException { + JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); + elementAdapter.write(out, obj); + } + + @Override + public MDLItem read(JsonReader in) throws IOException { + JsonElement jsonElement = elementAdapter.read(in); + validateJsonElement(jsonElement); + return thisAdapter.fromJsonTree(jsonElement); + } + }.nullSafe(); + } + } + + /** + * Create an instance of MDLItem given an JSON string + * + * @param jsonString JSON string + * @return An instance of MDLItem + * @throws IOException if the JSON string is invalid with respect to MDLItem + */ + public static MDLItem fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, MDLItem.class); + } + + /** + * Convert an instance of MDLItem to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } +} diff --git a/client/src/main/generated/com/regula/documentreader/webclient/model/MDLResult.java b/client/src/main/generated/com/regula/documentreader/webclient/model/MDLResult.java new file mode 100644 index 0000000..61796ff --- /dev/null +++ b/client/src/main/generated/com/regula/documentreader/webclient/model/MDLResult.java @@ -0,0 +1,201 @@ +/* + * Regula Document Reader Web API + * 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 + * + * The version of the OpenAPI document: 8.1.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.regula.documentreader.webclient.model; + +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.TypeAdapter; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.annotations.SerializedName; +import com.google.gson.reflect.TypeToken; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import com.regula.documentreader.webclient.JSON; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Objects; + +/** MDLResult */ +@javax.annotation.Generated( + value = "org.openapitools.codegen.languages.JavaClientCodegen", + comments = "Generator version: 7.15.0") +public class MDLResult extends ResultItem { + public static final String SERIALIZED_NAME_MD_L_PARSED_RESPONSE = "MDLParsedResponse"; + + @SerializedName(SERIALIZED_NAME_MD_L_PARSED_RESPONSE) + @javax.annotation.Nonnull + private Map mdLParsedResponse; + + public MDLResult() {} + + public MDLResult mdLParsedResponse( + @javax.annotation.Nonnull Map mdLParsedResponse) { + this.mdLParsedResponse = mdLParsedResponse; + return this; + } + + public MDLResult putMdLParsedResponseItem(String key, Object mdLParsedResponseItem) { + if (this.mdLParsedResponse == null) { + this.mdLParsedResponse = new HashMap<>(); + } + this.mdLParsedResponse.put(key, mdLParsedResponseItem); + return this; + } + + /** + * Get mdLParsedResponse + * + * @return mdLParsedResponse + */ + @javax.annotation.Nonnull + public Map getMdLParsedResponse() { + return mdLParsedResponse; + } + + public void setMdLParsedResponse( + @javax.annotation.Nonnull Map mdLParsedResponse) { + this.mdLParsedResponse = mdLParsedResponse; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + MDLResult mdLResult = (MDLResult) o; + return Objects.equals(this.mdLParsedResponse, mdLResult.mdLParsedResponse) && super.equals(o); + } + + @Override + public int hashCode() { + return Objects.hash(mdLParsedResponse, super.hashCode()); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class MDLResult {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); + sb.append(" mdLParsedResponse: ").append(toIndentedString(mdLParsedResponse)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + public static HashSet openapiFields; + public static HashSet openapiRequiredFields; + + static { + // a set of all properties/fields (JSON key names) + openapiFields = + new HashSet( + Arrays.asList( + "buf_length", "light", "list_idx", "page_idx", "result_type", "MDLParsedResponse")); + + // a set of required properties/fields (JSON key names) + openapiRequiredFields = new HashSet(Arrays.asList("MDLParsedResponse", "result_type")); + } + + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to MDLResult + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + if (jsonElement == null) { + if (!MDLResult.openapiRequiredFields + .isEmpty()) { // has required fields but JSON element is null + System.err.println( + String.format( + "The required field(s) %s in MDLResult is not found in the empty JSON string", + MDLResult.openapiRequiredFields.toString())); + } + } + + // check to make sure all required properties/fields are present in the JSON string + for (String requiredField : MDLResult.openapiRequiredFields) { + if (jsonElement.getAsJsonObject().get(requiredField) == null) { + System.err.println( + String.format( + "The required field `%s` is not found in the JSON string: %s", + requiredField, jsonElement.toString())); + } + } + } + + public static class CustomTypeAdapterFactory implements TypeAdapterFactory { + @SuppressWarnings("unchecked") + @Override + public TypeAdapter create(Gson gson, TypeToken type) { + if (!MDLResult.class.isAssignableFrom(type.getRawType())) { + return null; // this class only serializes 'MDLResult' and its subtypes + } + final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); + final TypeAdapter thisAdapter = + gson.getDelegateAdapter(this, TypeToken.get(MDLResult.class)); + + return (TypeAdapter) + new TypeAdapter() { + @Override + public void write(JsonWriter out, MDLResult value) throws IOException { + JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); + elementAdapter.write(out, obj); + } + + @Override + public MDLResult read(JsonReader in) throws IOException { + JsonElement jsonElement = elementAdapter.read(in); + validateJsonElement(jsonElement); + return thisAdapter.fromJsonTree(jsonElement); + } + }.nullSafe(); + } + } + + /** + * Create an instance of MDLResult given an JSON string + * + * @param jsonString JSON string + * @return An instance of MDLResult + * @throws IOException if the JSON string is invalid with respect to MDLResult + */ + public static MDLResult fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, MDLResult.class); + } + + /** + * Convert an instance of MDLResult to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } +} diff --git a/client/src/main/generated/com/regula/documentreader/webclient/model/ResultItem.java b/client/src/main/generated/com/regula/documentreader/webclient/model/ResultItem.java index d0b67b6..6468f90 100644 --- a/client/src/main/generated/com/regula/documentreader/webclient/model/ResultItem.java +++ b/client/src/main/generated/com/regula/documentreader/webclient/model/ResultItem.java @@ -249,6 +249,9 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti case "109": ByteArrayResult.validateJsonElement(jsonElement); break; + case "121": + MDLResult.validateJsonElement(jsonElement); + break; case "124": VDSNCDataResult.validateJsonElement(jsonElement); break;