/*
 * Michelin North America Order-to-Cash APIs
 * These APIs will help you to do business transactions with Michelin.  <br><br><b>Authentication details:</b><br> <br><u>Option A:</u> OAuth2 Client Credentials (recommended) <br><u>Option B:</u> API Key + Basic Authentication (not recommended) <br><br>To request your access, please contact your representative. <br><br>Our services are based on the EDIWHEEL standards. <br>You can find more information on the <a href=\"https://www.ediwheel.com/\" target=\"_blank\">EDIWHEEL website</a>. 
 *
 * The version of the OpenAPI document: 1.0.1
 * 
 *
 * 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.michelin.adk.amn;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
import com.google.gson.TypeAdapter;
import com.google.gson.internal.bind.util.ISO8601Utils;
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.text.ParsePosition;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
import java.util.HashMap;

/*
 * 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();

    @SuppressWarnings("unchecked")
    public static GsonBuilder createGson() {
        GsonFireBuilder fireBuilder = new GsonFireBuilder()
        ;
        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.michelin.adk.amn.o2c.model.AuthenticationError.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.AuthenticationTokenResponse.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.BuyersArticleIDIsUsed.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListRequest.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListRequestInvoiceInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListRequestInvoiceInnerBuyerParty.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListRequestInvoiceInnerConsignee.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListRequestInvoiceInnerReferences.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponse.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseErrorHead.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerAllowanceOrChargeInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerAllowanceOrChargeInnerAllowanceOrChargeAmount.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerAttachmentsInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerBuyerParty.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerBuyerPartyAddress.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerConsignee.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerConsigneeAddress.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerControls.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerHeaderNote.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerInvoiceIssuerParty.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerInvoiceIssuerPartyAddress.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerLineLevelInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerLineLevelInnerArticle.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerLineLevelInnerArticleAllowanceOrChargeInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerLineLevelInnerArticleAllowanceOrChargeInnerAllowanceOrChargeAmount.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerLineLevelInnerArticleArticleDescriptionInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerLineLevelInnerArticleArticleIdentification.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerLineLevelInnerArticleConsignee.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerLineLevelInnerArticleInvoicedQuantity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerLineLevelInnerArticleLineItemTotalAmount.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerLineLevelInnerArticleLineNote.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerLineLevelInnerArticlePriceDetails.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerLineLevelInnerArticlePriceDetailsGrossUnitPrice.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerLineLevelInnerArticlePriceDetailsNetUnitPrice.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerLineLevelInnerArticleTaxDetailsInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerLineLevelInnerArticleTaxDetailsInnerTaxAmount.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerLineLevelInnerArticleTracingInformationInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerLineLevelInnerLineItemNetAmount.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerLineLevelInnerReferences.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerLineLevelInnerReferencesAssociatedInvoiceReference.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerLineLevelInnerReferencesBuyerOrderReference.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerLineLevelInnerReferencesDeliveryNoteReference.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerLineLevelInnerReferencesSuppliersOrderReference.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerPaymentTermsInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerPaymentTermsInnerPaymentNetInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerPaymentTermsInnerPaymentNetInnerInstalmentAmount.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerReferences.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerReferencesFleetReferenceInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerReferencesSupplierClaimNumber.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerSellerParty.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerSellerPartyAddress.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerSellerPartyInformationContact.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerSellerPartySupplierParty.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerSellerPartySupplierPartyShippingLocation.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerSummary.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerSummaryTaxDetailsInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerSummaryTaxDetailsInnerTaxAmount.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerSummaryTaxDetailsInnerTaxableAmount.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerSummaryTotalAmount.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListResponseInvoiceInnerSummaryTotalLineItemsAmount.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC10DesadvRequest.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC10DesadvRequestBuyerParty.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC10DesadvRequestConsignee.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC10DesadvRequestReferences.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC10DesadvResponse.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC10DesadvResponseDesadvInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC10DesadvResponseDesadvInnerBuyerParty.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC10DesadvResponseDesadvInnerCarrierParty.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC10DesadvResponseDesadvInnerConsignee.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC10DesadvResponseDesadvInnerConsigneeAddress.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC10DesadvResponseDesadvInnerLineLevelInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticle.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticleArticleDescription.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticleArticleIdentification.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticleDespatchedQuantity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticleTracingInformationInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerReferencesInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC10DesadvResponseDesadvInnerMeasures.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC10DesadvResponseDesadvInnerMeasuresGrossWeight.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC10DesadvResponseDesadvInnerReferencesInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC10DesadvResponseDesadvInnerTotalQuantity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC10DesadvResponseEnvelopeHeader.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC10DesadvResponseErrorHead.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationRequest.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationRequestAllOfAdditionalCustomerReferenceNumber.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationRequestAllOfBuyerParty.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationRequestAllOfConsignee.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationRequestAllOfCustomerReference.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationRequestAllOfOrderLine.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationRequestAllOfOrderedArticle.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationRequestAllOfOrderedArticleArticleIdentification.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationRequestAllOfOrderedArticleRequestedQuantity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationRequestAllOfSupplierParty.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationRequestAllOfSupplierPartyAddress.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationRequestAllOfSupplierPartyInformationContact.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationResponse.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationResponseBuyerParty.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationResponseConsignee.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationResponseCustomerReference.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationResponseErrorHead.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationResponseOrderLineInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationResponseOrderLineInnerAdditionalCustomerReferenceNumber.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationResponseOrderLineInnerOrderedArticle.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationResponseOrderLineInnerOrderedArticleArticleDescription.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationResponseOrderLineInnerOrderedArticleArticleIdentification.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationResponseOrderLineInnerOrderedArticleError.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationResponseOrderLineInnerOrderedArticleOrderReference.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationResponseOrderLineInnerOrderedArticleOrderedQuantity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationResponseOrderLineInnerOrderedArticleScheduleDetailsInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationResponseOrderLineInnerOrderedArticleScheduleDetailsInnerChargeInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationResponseOrderLineInnerOrderedArticleScheduleDetailsInnerChargeInnerChargeAmount.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationResponseOrderLineInnerOrderedArticleScheduleDetailsInnerConfirmedQuantity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationResponseOrderLineInnerOrderedArticleScheduleDetailsInnerPriceDetails.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationResponseOrderLineInnerOrderedArticleScheduleDetailsInnerPriceDetailsNetUnitPrice.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationResponseSupplierParty.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationResponseSupplierPartyAddress.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderCreationResponseSupplierPartyInformationContact.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusRequest.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusRequestBuyerParty.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusRequestConsignee.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusRequestReferencedOrderInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusRequestReferencedOrderInnerOrderReference.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusRequestReferencedOrderInnerOrderedArticle.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusRequestReferencedOrderInnerOrderedArticleArticleIdentification.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusRequestReferencedOrderInnerSupplierOrderNumber.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusResponse.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusResponseBuyerParty.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusResponseConsignee.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusResponseReferencedOrderInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderLineInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderLineInnerOrderedArticle.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderLineInnerOrderedArticleArticleDescription.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderLineInnerOrderedArticleArticleIdentification.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderLineInnerOrderedArticleOrderedQuantity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderLineInnerOrderedArticleScheduleDetailsInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderLineInnerOrderedArticleScheduleDetailsInnerBackorderedQuantity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderLineInnerOrderedArticleScheduleDetailsInnerCancelledQuantity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderLineInnerOrderedArticleScheduleDetailsInnerConfirmedQuantity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderLineInnerOrderedArticleScheduleDetailsInnerOpenQuantity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderLineInnerOrderedArticleScheduleDetailsInnerScheduledQuantity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderLineInnerOrderedArticleScheduleDetailsInnerShippedDetails.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderLineInnerOrderedArticleScheduleDetailsInnerShippedDetailsDespatchedDetails.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderLineInnerOrderedArticleScheduleDetailsInnerShippedDetailsDespatchedDetailsScheduledArticleDespatchDetailsInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderLineInnerOrderedArticleScheduleDetailsInnerShippedDetailsDespatchedDetailsScheduledArticleDespatchDetailsInnerDespatchAdviceReference.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderLineInnerOrderedArticleScheduleDetailsInnerShippedDetailsDespatchedDetailsScheduledArticleDespatchDetailsInnerDespatchedQuantity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderLineInnerOrderedArticleScheduleDetailsInnerShippedDetailsShippedQuantity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderReference.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusResponseReferencedOrderInnerSupplierOrderNumber.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11StockInquiryRequest.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11StockInquiryRequestBuyerParty.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11StockInquiryRequestConsignee.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11StockInquiryRequestOrderLineInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11StockInquiryRequestOrderLineInnerOrderedArticle.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11StockInquiryRequestOrderLineInnerOrderedArticleArticleIdentification.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11StockInquiryRequestOrderLineInnerOrderedArticleRequestedQuantity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11StockInquiryResponse.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11StockInquiryResponseBuyerParty.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11StockInquiryResponseConsignee.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11StockInquiryResponseErrorHead.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11StockInquiryResponseOrderLineInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11StockInquiryResponseOrderLineInnerOrderedArticle.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11StockInquiryResponseOrderLineInnerOrderedArticleArticleIdentification.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11StockInquiryResponseOrderLineInnerOrderedArticleError.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11StockInquiryResponseOrderLineInnerOrderedArticleRequestedQuantity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11StockInquiryResponseOrderLineInnerOrderedArticleScheduleDetailsInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11StockInquiryResponseOrderLineInnerOrderedArticleScheduleDetailsInnerAvailableQuantity.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11StockInquiryResponseOrderLineInnerOrderedArticleScheduleDetailsInnerChargeInner.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11StockInquiryResponseOrderLineInnerOrderedArticleScheduleDetailsInnerChargeInnerChargeAmount.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11StockInquiryResponseOrderLineInnerOrderedArticleScheduleDetailsInnerPriceDetails.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11StockInquiryResponseOrderLineInnerOrderedArticleScheduleDetailsInnerPriceDetailsNetUnitPrice.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11StockInquiryResponseOrderLineInnerOrderedArticleScheduleDetailsInnerSupplierParty.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11StockInquiryResponseOrderLineInnerOrderedArticleScheduleDetailsInnerSupplierPartyAddress.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.EDIWheelC11StockInquiryResponseOrderLineInnerOrderedArticleScheduleDetailsInnerSupplierPartyInformationContact.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.GeneralError.CustomTypeAdapterFactory());
        gsonBuilder.registerTypeAdapterFactory(new com.michelin.adk.amn.o2c.model.ManufacturersArticleIDIsUsed.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 <T>        Type
     * @param body       The JSON string
     * @param returnType The type to deserialize into
     * @return The deserialized Java object
     */
    @SuppressWarnings("unchecked")
    public static <T> 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<byte[]> {

        @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<OffsetDateTime> {

        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<LocalDate> {

        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<java.sql.Date> {

        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(ISO8601Utils.parse(date, new ParsePosition(0)).getTime());
                    } catch (ParseException e) {
                        throw new JsonParseException(e);
                    }
            }
        }
    }

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

        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 = ISO8601Utils.format(date, true);
                }
                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 ISO8601Utils.parse(date, new ParsePosition(0));
                        } 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);
    }
}
