All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.onfido.JSON Maven / Gradle / Ivy

/*
 * Onfido API v3.6
 * The Onfido API (v3.6)
 *
 * The version of the OpenAPI document: v3.6
 * 
 *
 * 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.onfido;

import com.fasterxml.jackson.databind.util.StdDateFormat;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import com.google.gson.JsonElement;
import io.gsonfire.GsonFireBuilder;
import io.gsonfire.TypeSelector;

import okio.ByteString;

import java.io.IOException;
import java.io.StringReader;
import java.lang.reflect.Type;
import java.text.DateFormat;
import java.text.ParseException;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
import java.util.HashMap;
import java.util.TimeZone;

/*
 * A JSON utility class
 *
 * NOTE: in the future, this class may be converted to static, which may break
 *       backward-compatibility
 */
public class JSON {
    private static Gson gson;
    private static boolean isLenientOnJson = false;
    private static DateTypeAdapter dateTypeAdapter = new DateTypeAdapter();
    private static SqlDateTypeAdapter sqlDateTypeAdapter = new SqlDateTypeAdapter();
    private static OffsetDateTimeTypeAdapter offsetDateTimeTypeAdapter = new OffsetDateTimeTypeAdapter();
    private static LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter();
    private static ByteArrayAdapter byteArrayAdapter = new ByteArrayAdapter();

    private static final StdDateFormat sdf = new StdDateFormat()
        .withTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault()))
        .withColonInTimeZone(true);
    private static final DateTimeFormatter dtf = DateTimeFormatter.ISO_OFFSET_DATE_TIME;

    @SuppressWarnings("unchecked")
    public static GsonBuilder createGson() {
        GsonFireBuilder fireBuilder = new GsonFireBuilder()
                .registerTypeSelector(com.onfido.model.Report.class, new TypeSelector() {
                    @Override
                    public Class getClassForElement(JsonElement readElement) {
                        Map classByDiscriminatorValue = new HashMap();
                        classByDiscriminatorValue.put("device_intelligence", com.onfido.model.DeviceIntelligenceReport.class);
                        classByDiscriminatorValue.put("document", com.onfido.model.DocumentReport.class);
                        classByDiscriminatorValue.put("document_video", com.onfido.model.DocumentVideoReport.class);
                        classByDiscriminatorValue.put("document_video_with_address_information", com.onfido.model.DocumentVideoWithAddressInformationReport.class);
                        classByDiscriminatorValue.put("document_with_address_information", com.onfido.model.DocumentWithAddressInformationReport.class);
                        classByDiscriminatorValue.put("document_with_driver_verification", com.onfido.model.DocumentWithDriverVerificationReport.class);
                        classByDiscriminatorValue.put("document_with_driving_licence_information", com.onfido.model.DocumentWithDrivingLicenceInformationReport.class);
                        classByDiscriminatorValue.put("facial_similarity_motion", com.onfido.model.FacialSimilarityMotionReport.class);
                        classByDiscriminatorValue.put("facial_similarity_photo", com.onfido.model.FacialSimilarityPhotoReport.class);
                        classByDiscriminatorValue.put("facial_similarity_photo_fully_auto", com.onfido.model.FacialSimilarityPhotoFullyAutoReport.class);
                        classByDiscriminatorValue.put("facial_similarity_video", com.onfido.model.FacialSimilarityVideoReport.class);
                        classByDiscriminatorValue.put("identity_enhanced", com.onfido.model.IdentityEnhancedReport.class);
                        classByDiscriminatorValue.put("india_pan", com.onfido.model.IndiaPanReport.class);
                        classByDiscriminatorValue.put("known_faces", com.onfido.model.KnownFacesReport.class);
                        classByDiscriminatorValue.put("proof_of_address", com.onfido.model.ProofOfAddressReport.class);
                        classByDiscriminatorValue.put("us_driving_licence", com.onfido.model.UsDrivingLicenceReport.class);
                        classByDiscriminatorValue.put("watchlist_aml", com.onfido.model.WatchlistAmlReport.class);
                        classByDiscriminatorValue.put("watchlist_enhanced", com.onfido.model.WatchlistEnhancedReport.class);
                        classByDiscriminatorValue.put("watchlist_peps_only", com.onfido.model.WatchlistPepsOnlyReport.class);
                        classByDiscriminatorValue.put("watchlist_sanctions_only", com.onfido.model.WatchlistSanctionsOnlyReport.class);
                        classByDiscriminatorValue.put("watchlist_standard", com.onfido.model.WatchlistStandardReport.class);
                        classByDiscriminatorValue.put("device_intelligence_report", com.onfido.model.DeviceIntelligenceReport.class);
                        classByDiscriminatorValue.put("document_report", com.onfido.model.DocumentReport.class);
                        classByDiscriminatorValue.put("document_video_report", com.onfido.model.DocumentVideoReport.class);
                        classByDiscriminatorValue.put("document_video_with_address_information_report", com.onfido.model.DocumentVideoWithAddressInformationReport.class);
                        classByDiscriminatorValue.put("document_with_address_information_report", com.onfido.model.DocumentWithAddressInformationReport.class);
                        classByDiscriminatorValue.put("document_with_driver_verification_report", com.onfido.model.DocumentWithDriverVerificationReport.class);
                        classByDiscriminatorValue.put("document_with_driving_licence_information_report", com.onfido.model.DocumentWithDrivingLicenceInformationReport.class);
                        classByDiscriminatorValue.put("facial_similarity_motion_report", com.onfido.model.FacialSimilarityMotionReport.class);
                        classByDiscriminatorValue.put("facial_similarity_photo_fully_auto_report", com.onfido.model.FacialSimilarityPhotoFullyAutoReport.class);
                        classByDiscriminatorValue.put("facial_similarity_photo_report", com.onfido.model.FacialSimilarityPhotoReport.class);
                        classByDiscriminatorValue.put("facial_similarity_video_report", com.onfido.model.FacialSimilarityVideoReport.class);
                        classByDiscriminatorValue.put("identity_enhanced_report", com.onfido.model.IdentityEnhancedReport.class);
                        classByDiscriminatorValue.put("india_pan_report", com.onfido.model.IndiaPanReport.class);
                        classByDiscriminatorValue.put("known_faces_report", com.onfido.model.KnownFacesReport.class);
                        classByDiscriminatorValue.put("proof_of_address_report", com.onfido.model.ProofOfAddressReport.class);
                        classByDiscriminatorValue.put("us_driving_licence_report", com.onfido.model.UsDrivingLicenceReport.class);
                        classByDiscriminatorValue.put("watchlist_aml_report", com.onfido.model.WatchlistAmlReport.class);
                        classByDiscriminatorValue.put("watchlist_enhanced_report", com.onfido.model.WatchlistEnhancedReport.class);
                        classByDiscriminatorValue.put("watchlist_peps_only_report", com.onfido.model.WatchlistPepsOnlyReport.class);
                        classByDiscriminatorValue.put("watchlist_sanctions_only_report", com.onfido.model.WatchlistSanctionsOnlyReport.class);
                        classByDiscriminatorValue.put("watchlist_standard_report", com.onfido.model.WatchlistStandardReport.class);
                        classByDiscriminatorValue.put("report", com.onfido.model.Report.class);
                        return getClassByDiscriminator(classByDiscriminatorValue,
                                getDiscriminatorValue(readElement, "name"));
                    }
          })
        ;
        GsonBuilder builder = fireBuilder.createGsonBuilder();
        return builder;
    }

    private static String getDiscriminatorValue(JsonElement readElement, String discriminatorField) {
        JsonElement element = readElement.getAsJsonObject().get(discriminatorField);
        if (null == element) {
            throw new IllegalArgumentException("missing discriminator field: <" + discriminatorField + ">");
        }
        return element.getAsString();
    }

    /**
     * Returns the Java class that implements the OpenAPI schema for the specified discriminator value.
     *
     * @param classByDiscriminatorValue The map of discriminator values to Java classes.
     * @param discriminatorValue The value of the OpenAPI discriminator in the input data.
     * @return The Java class that implements the OpenAPI schema
     */
    private static Class getClassByDiscriminator(Map classByDiscriminatorValue, String discriminatorValue) {
        Class clazz = (Class) classByDiscriminatorValue.get(discriminatorValue);
        if (null == clazz) {
            throw new IllegalArgumentException("cannot determine model class of name: <" + discriminatorValue + ">");
        }
        return clazz;
    }

    static {
        GsonBuilder gsonBuilder = createGson();
        gsonBuilder.registerTypeAdapter(Date.class, dateTypeAdapter);
        gsonBuilder.registerTypeAdapter(java.sql.Date.class, sqlDateTypeAdapter);
        gsonBuilder.registerTypeAdapter(OffsetDateTime.class, offsetDateTimeTypeAdapter);
        gsonBuilder.registerTypeAdapter(LocalDate.class, localDateTypeAdapter);
        gsonBuilder.registerTypeAdapter(byte[].class, byteArrayAdapter);
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.Address.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.AddressBuilder.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.AddressShared.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.AddressesList.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.Applicant.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.ApplicantBuilder.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.ApplicantCreate.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.ApplicantRequest.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.ApplicantResponse.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.ApplicantShared.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.ApplicantUpdate.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.ApplicantUpdater.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.ApplicantsList.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.Check.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.CheckBuilder.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.CheckRequest.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.CheckResponse.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.CheckShared.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.ChecksList.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.CompleteTaskBuilder.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.CompleteTaskDataBuilder.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.ConsentItem.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.ConsentsBuilder.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DeviceIntelligenceBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DeviceIntelligenceBreakdownBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DeviceIntelligenceBreakdownBreakdownDevice.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DeviceIntelligenceBreakdownBreakdownDeviceBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DeviceIntelligenceBreakdownProperties.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DeviceIntelligenceBreakdownPropertiesDevice.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DeviceIntelligenceBreakdownPropertiesGeolocation.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DeviceIntelligenceBreakdownPropertiesIp.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DeviceIntelligenceReport.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.Document.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownAgeValidation.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownAgeValidationBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownCompromisedDocument.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownCompromisedDocumentBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownDataComparison.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownDataComparisonBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownDataComparisonBreakdownIssuingCountry.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownDataConsistency.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownDataConsistencyBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownDataValidation.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownDataValidationBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownDataValidationBreakdownDocumentExpiration.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownDataValidationBreakdownExpiryDate.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownImageIntegrity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownImageIntegrityBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownImageIntegrityBreakdownColourPicture.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownImageIntegrityBreakdownConclusiveDocumentQuality.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownImageIntegrityBreakdownImageQuality.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownImageIntegrityBreakdownSupportedDocument.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownIssuingAuthority.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownIssuingAuthorityBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownIssuingAuthorityBreakdownNfcActiveAuthentication.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownIssuingAuthorityBreakdownNfcPassiveAuthentication.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownPoliceRecord.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownVisualAuthenticity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownVisualAuthenticityBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownVisualAuthenticityBreakdownDigitalTampering.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownVisualAuthenticityBreakdownFaceDetection.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownVisualAuthenticityBreakdownFonts.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownVisualAuthenticityBreakdownOriginalDocumentPresent.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownVisualAuthenticityBreakdownOther.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownVisualAuthenticityBreakdownPictureFaceIntegrity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownVisualAuthenticityBreakdownSecurityFeatures.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentBreakdownVisualAuthenticityBreakdownTemplate.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentCDQReasons.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentIQReasons.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentODPReasons.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentProperties.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentPropertiesAddressLines.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentPropertiesBarcodeInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentPropertiesDocumentClassification.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentPropertiesDocumentNumbersInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentPropertiesDrivingLicenceInformation.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentPropertiesExtractedData.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentPropertiesNfc.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentReport.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentResponse.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentShared.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentVideoReport.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentVideoWithAddressInformationReport.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentWithAddressInformationReport.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentWithDriverVerificationReport.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentWithDriverVerificationReportAllOfProperties.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentWithDriverVerificationReportAllOfPropertiesAllOfPassengerVehicle.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentWithDriverVerificationReportAllOfPropertiesAllOfVehicleClassDetailsInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentWithDrivingLicenceInformationReport.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.DocumentsList.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.Error.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.Error1.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.ErrorProperties.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.ErrorProperties1.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.ExtractRequest.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.Extraction.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.ExtractionDocumentClassification.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.ExtractionExtractedData.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityMotionBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityMotionBreakdownFaceComparison.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityMotionBreakdownImageIntegrity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityMotionBreakdownImageIntegrityBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityMotionBreakdownImageIntegrityBreakdownFaceDetected.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityMotionBreakdownImageIntegrityBreakdownSourceIntegrity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityMotionBreakdownVisualAuthenticity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityMotionBreakdownVisualAuthenticityBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityMotionBreakdownVisualAuthenticityBreakdownSpoofingDetection.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityMotionProperties.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityMotionReport.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityPhotoBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityPhotoBreakdownFaceComparison.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityPhotoBreakdownFaceComparisonBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityPhotoBreakdownFaceComparisonBreakdownFaceMatch.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityPhotoBreakdownFaceComparisonBreakdownFaceMatchProperties.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityPhotoBreakdownImageIntegrity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityPhotoBreakdownImageIntegrityBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityPhotoBreakdownImageIntegrityBreakdownFaceDetected.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityPhotoBreakdownImageIntegrityBreakdownSourceIntegrity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityPhotoBreakdownVisualAuthenticity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityPhotoBreakdownVisualAuthenticityBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityPhotoBreakdownVisualAuthenticityBreakdownSpoofingDetection.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityPhotoBreakdownVisualAuthenticityBreakdownSpoofingDetectionProperties.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityPhotoFullyAutoBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityPhotoFullyAutoBreakdownImageIntegrity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityPhotoFullyAutoBreakdownImageIntegrityBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityPhotoFullyAutoBreakdownImageIntegrityBreakdownSourceIntegrity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityPhotoFullyAutoProperties.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityPhotoFullyAutoReport.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityPhotoProperties.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityPhotoReport.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityVideoBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityVideoBreakdownFaceComparison.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityVideoBreakdownImageIntegrity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityVideoBreakdownImageIntegrityBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityVideoBreakdownImageIntegrityBreakdownFaceDetected.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityVideoBreakdownImageIntegrityBreakdownSourceIntegrity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityVideoBreakdownVisualAuthenticity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityVideoBreakdownVisualAuthenticityBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityVideoBreakdownVisualAuthenticityBreakdownLivenessDetected.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityVideoBreakdownVisualAuthenticityBreakdownSpoofingDetection.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityVideoProperties.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.FacialSimilarityVideoReport.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IdNumber.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IdPhoto.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IdPhotoResponse.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IdPhotosList.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IdentityEnhancedBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IdentityEnhancedBreakdownAddress.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IdentityEnhancedBreakdownAddressBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IdentityEnhancedBreakdownAddressBreakdownCreditAgencies.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IdentityEnhancedBreakdownAddressBreakdownCreditAgenciesProperties.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IdentityEnhancedBreakdownAddressBreakdownTelephoneDatabase.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IdentityEnhancedBreakdownAddressBreakdownVotingRegister.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IdentityEnhancedBreakdownDateOfBirth.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IdentityEnhancedBreakdownDateOfBirthBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IdentityEnhancedBreakdownDateOfBirthBreakdownCreditAgencies.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IdentityEnhancedBreakdownDateOfBirthBreakdownVotingRegister.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IdentityEnhancedBreakdownMortality.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IdentityEnhancedBreakdownSources.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IdentityEnhancedBreakdownSourcesBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IdentityEnhancedBreakdownSourcesBreakdownTotalSources.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IdentityEnhancedBreakdownSourcesBreakdownTotalSourcesProperties.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IdentityEnhancedProperties.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IdentityEnhancedPropertiesMatchedAddressesInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IdentityEnhancedReport.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IndiaPanReport.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IndiaPanReportAllOfBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IndiaPanReportAllOfBreakdownDevice.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IndiaPanReportAllOfBreakdownDeviceBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IndiaPanReportAllOfBreakdownDeviceBreakdownPanValid.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IndiaPanReportAllOfProperties.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.IndiaPanReportAllOfPropertiesDevice.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.KnownFacesBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.KnownFacesBreakdownImageIntegrity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.KnownFacesBreakdownPreviouslySeenFaces.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.KnownFacesProperties.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.KnownFacesPropertiesMatchesInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.KnownFacesReport.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.LivePhoto.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.LivePhotoResponse.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.LivePhotosList.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.LiveVideo.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.LiveVideosList.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.Location.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.LocationBuilder.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.LocationShared.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.MotionCapture.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.MotionCapturesList.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.PhotoAutoReasons.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.PhotoReasons.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.ProofOfAddressBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.ProofOfAddressBreakdownDataComparison.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.ProofOfAddressBreakdownDataComparisonBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.ProofOfAddressBreakdownDocumentClassification.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.ProofOfAddressBreakdownDocumentClassificationBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.ProofOfAddressBreakdownImageIntegrity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.ProofOfAddressBreakdownImageIntegrityBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.ProofOfAddressProperties.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.ProofOfAddressReport.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.RepeatAttemptsList.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.RepeatAttemptsListRepeatAttemptsInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.Report.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.ReportDocument.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.ReportShared.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.ReportsList.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.ResultsFeedback.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.SdkToken.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.SdkTokenBuilder.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.SdkTokenRequest.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.SdkTokenResponse.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.Task.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.TaskItem.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.TimelineFileReference.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.UsDrivingLicenceBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.UsDrivingLicenceBreakdownAddress.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.UsDrivingLicenceBreakdownAddressBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.UsDrivingLicenceBreakdownDocument.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.UsDrivingLicenceBreakdownDocumentBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.UsDrivingLicenceBreakdownPersonal.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.UsDrivingLicenceBreakdownPersonalBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.UsDrivingLicenceBuilder.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.UsDrivingLicenceReport.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.UsDrivingLicenceShared.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.VideoReasons.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistAmlBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistAmlBreakdownAdverseMedia.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistAmlBreakdownLegalAndRegulatoryWarnings.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistAmlBreakdownPoliticallyExposedPerson.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistAmlBreakdownSanction.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistAmlProperties.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistAmlReport.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistEnhancedBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistEnhancedProperties.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistEnhancedPropertiesRecordsInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistEnhancedPropertiesRecordsInnerAddressInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistEnhancedPropertiesRecordsInnerAliasInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistEnhancedPropertiesRecordsInnerAssociateInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistEnhancedPropertiesRecordsInnerAttributeInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistEnhancedPropertiesRecordsInnerEventInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistEnhancedPropertiesRecordsInnerEventInnerSource.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistEnhancedPropertiesRecordsInnerSourceInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistEnhancedReport.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistMonitor.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistMonitorBuilder.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistMonitorMatch.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistMonitorMatchesList.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistMonitorMatchesUpdater.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistMonitorResponse.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistMonitorShared.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistMonitorsList.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistPepsOnlyReport.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistSanctionsOnlyReport.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistStandardBreakdown.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistStandardProperties.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WatchlistStandardReport.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.Webhook.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WebhookBuilder.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WebhookCreate.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WebhookEvent.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WebhookEventPayload.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WebhookEventPayloadObject.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WebhookResend.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WebhookResponse.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WebhookShared.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WebhookUpdate.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WebhookUpdater.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WebhooksList.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WebhooksResendItem.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WorkflowRun.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WorkflowRunBuilder.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WorkflowRunRequest.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WorkflowRunResponse.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WorkflowRunResponseError.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WorkflowRunShared.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.onfido.model.WorkflowRunSharedLink.CustomTypeAdapterFactory());
        gson = gsonBuilder.create();
    }

    /**
     * Get Gson.
     *
     * @return Gson
     */
    public static Gson getGson() {
        return gson;
    }

    /**
     * Set Gson.
     *
     * @param gson Gson
     */
    public static void setGson(Gson gson) {
        JSON.gson = gson;
    }

    public static void setLenientOnJson(boolean lenientOnJson) {
        isLenientOnJson = lenientOnJson;
    }

    /**
     * Serialize the given Java object into JSON string.
     *
     * @param obj Object
     * @return String representation of the JSON
     */
    public static String serialize(Object obj) {
        return gson.toJson(obj);
    }

    /**
     * Deserialize the given JSON string to Java object.
     *
     * @param         Type
     * @param body       The JSON string
     * @param returnType The type to deserialize into
     * @return The deserialized Java object
     */
    @SuppressWarnings("unchecked")
    public static  T deserialize(String body, Type returnType) {
        try {
            if (isLenientOnJson) {
                JsonReader jsonReader = new JsonReader(new StringReader(body));
                // see https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/stream/JsonReader.html#setLenient(boolean)
                jsonReader.setLenient(true);
                return gson.fromJson(jsonReader, returnType);
            } else {
                return gson.fromJson(body, returnType);
            }
        } catch (JsonParseException e) {
            // Fallback processing when failed to parse JSON form response body:
            // return the response body string directly for the String return type;
            if (returnType.equals(String.class)) {
                return (T) body;
            } else {
                throw (e);
            }
        }
    }

    /**
     * Gson TypeAdapter for Byte Array type
     */
    public static class ByteArrayAdapter extends TypeAdapter {

        @Override
        public void write(JsonWriter out, byte[] value) throws IOException {
            if (value == null) {
                out.nullValue();
            } else {
                out.value(ByteString.of(value).base64());
            }
        }

        @Override
        public byte[] read(JsonReader in) throws IOException {
            switch (in.peek()) {
                case NULL:
                    in.nextNull();
                    return null;
                default:
                    String bytesAsBase64 = in.nextString();
                    ByteString byteString = ByteString.decodeBase64(bytesAsBase64);
                    return byteString.toByteArray();
            }
        }
    }

    /**
     * Gson TypeAdapter for JSR310 OffsetDateTime type
     */
    public static class OffsetDateTimeTypeAdapter extends TypeAdapter {

        private DateTimeFormatter formatter;

        public OffsetDateTimeTypeAdapter() {
            this(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
        }

        public OffsetDateTimeTypeAdapter(DateTimeFormatter formatter) {
            this.formatter = formatter;
        }

        public void setFormat(DateTimeFormatter dateFormat) {
            this.formatter = dateFormat;
        }

        @Override
        public void write(JsonWriter out, OffsetDateTime date) throws IOException {
            if (date == null) {
                out.nullValue();
            } else {
                out.value(formatter.format(date));
            }
        }

        @Override
        public OffsetDateTime read(JsonReader in) throws IOException {
            switch (in.peek()) {
                case NULL:
                    in.nextNull();
                    return null;
                default:
                    String date = in.nextString();
                    if (date.endsWith("+0000")) {
                        date = date.substring(0, date.length()-5) + "Z";
                    }
                    return OffsetDateTime.parse(date, formatter);
            }
        }
    }

    /**
     * Gson TypeAdapter for JSR310 LocalDate type
     */
    public static class LocalDateTypeAdapter extends TypeAdapter {

        private DateTimeFormatter formatter;

        public LocalDateTypeAdapter() {
            this(DateTimeFormatter.ISO_LOCAL_DATE);
        }

        public LocalDateTypeAdapter(DateTimeFormatter formatter) {
            this.formatter = formatter;
        }

        public void setFormat(DateTimeFormatter dateFormat) {
            this.formatter = dateFormat;
        }

        @Override
        public void write(JsonWriter out, LocalDate date) throws IOException {
            if (date == null) {
                out.nullValue();
            } else {
                out.value(formatter.format(date));
            }
        }

        @Override
        public LocalDate read(JsonReader in) throws IOException {
            switch (in.peek()) {
                case NULL:
                    in.nextNull();
                    return null;
                default:
                    String date = in.nextString();
                    return LocalDate.parse(date, formatter);
            }
        }
    }

    public static void setOffsetDateTimeFormat(DateTimeFormatter dateFormat) {
        offsetDateTimeTypeAdapter.setFormat(dateFormat);
    }

    public static void setLocalDateFormat(DateTimeFormatter dateFormat) {
        localDateTypeAdapter.setFormat(dateFormat);
    }

    /**
     * Gson TypeAdapter for java.sql.Date type
     * If the dateFormat is null, a simple "yyyy-MM-dd" format will be used
     * (more efficient than SimpleDateFormat).
     */
    public static class SqlDateTypeAdapter extends TypeAdapter {

        private DateFormat dateFormat;

        public SqlDateTypeAdapter() {}

        public SqlDateTypeAdapter(DateFormat dateFormat) {
            this.dateFormat = dateFormat;
        }

        public void setFormat(DateFormat dateFormat) {
            this.dateFormat = dateFormat;
        }

        @Override
        public void write(JsonWriter out, java.sql.Date date) throws IOException {
            if (date == null) {
                out.nullValue();
            } else {
                String value;
                if (dateFormat != null) {
                    value = dateFormat.format(date);
                } else {
                    value = date.toString();
                }
                out.value(value);
            }
        }

        @Override
        public java.sql.Date read(JsonReader in) throws IOException {
            switch (in.peek()) {
                case NULL:
                    in.nextNull();
                    return null;
                default:
                    String date = in.nextString();
                    try {
                        if (dateFormat != null) {
                            return new java.sql.Date(dateFormat.parse(date).getTime());
                        }
                        return new java.sql.Date(sdf.parse(date).getTime());
                    } catch (ParseException e) {
                        throw new JsonParseException(e);
                    }
            }
        }
    }

    /**
     * Gson TypeAdapter for java.util.Date type
     * If the dateFormat is null, DateTimeFormatter will be used.
     */
    public static class DateTypeAdapter extends TypeAdapter {

        private DateFormat dateFormat;

        public DateTypeAdapter() {}

        public DateTypeAdapter(DateFormat dateFormat) {
            this.dateFormat = dateFormat;
        }

        public void setFormat(DateFormat dateFormat) {
            this.dateFormat = dateFormat;
        }

        @Override
        public void write(JsonWriter out, Date date) throws IOException {
            if (date == null) {
                out.nullValue();
            } else {
                String value;
                if (dateFormat != null) {
                    value = dateFormat.format(date);
                } else {
                    value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf);
                }
                out.value(value);
            }
        }

        @Override
        public Date read(JsonReader in) throws IOException {
            try {
                switch (in.peek()) {
                    case NULL:
                        in.nextNull();
                        return null;
                    default:
                        String date = in.nextString();
                        try {
                            if (dateFormat != null) {
                                return dateFormat.parse(date);
                            }
                            return sdf.parse(date);
                        } catch (ParseException e) {
                            throw new JsonParseException(e);
                        }
                }
            } catch (IllegalArgumentException e) {
                throw new JsonParseException(e);
            }
        }
    }

    public static void setDateFormat(DateFormat dateFormat) {
        dateTypeAdapter.setFormat(dateFormat);
    }

    public static void setSqlDateFormat(DateFormat dateFormat) {
        sqlDateTypeAdapter.setFormat(dateFormat);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy