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

com.zuora.model.BulkCreateDebitMemosRequest Maven / Gradle / Ivy

There is a newer version: 3.2.1
Show newest version
/*
 * Zuora API Reference
 * REST API reference for the Zuora Billing, Payments, and Central Platform! Check out the [REST API Overview](https://www.zuora.com/developer/api-references/api/overview/).
 *
 * The version of the OpenAPI document: 2024-05-20
 * Contact: [email protected]
 *
 * 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.zuora.model;

import java.util.Objects;
import com.google.gson.TypeAdapter;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import com.zuora.model.BulkCreateDebitMemosFromChargeRequest;
import com.zuora.model.BulkCreateDebitMemosFromInvoiceRequest;
import com.zuora.model.CreateDebitMemoFromCharge;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;



import java.io.IOException;
import java.lang.reflect.Type;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
import com.google.gson.JsonPrimitive;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonArray;
import com.google.gson.JsonParseException;

import com.zuora.JSON;

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.6.0")
public class BulkCreateDebitMemosRequest extends AbstractOpenApiSchema {
    private static final Logger log = Logger.getLogger(BulkCreateDebitMemosRequest.class.getName());

    public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
        @SuppressWarnings("unchecked")
        @Override
        public  TypeAdapter create(Gson gson, TypeToken type) {
            if (!BulkCreateDebitMemosRequest.class.isAssignableFrom(type.getRawType())) {
                return null; // this class only serializes 'BulkCreateDebitMemosRequest' and its subtypes
            }
            final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class);
            final TypeAdapter adapterBulkCreateDebitMemosFromInvoiceRequest = gson.getDelegateAdapter(this, TypeToken.get(BulkCreateDebitMemosFromInvoiceRequest.class));
            final TypeAdapter adapterBulkCreateDebitMemosFromChargeRequest = gson.getDelegateAdapter(this, TypeToken.get(BulkCreateDebitMemosFromChargeRequest.class));

            return (TypeAdapter) new TypeAdapter() {
                @Override
                public void write(JsonWriter out, BulkCreateDebitMemosRequest value) throws IOException {
                    if (value == null || value.getActualInstance() == null) {
                        elementAdapter.write(out, null);
                        return;
                    }

                    // check if the actual instance is of the type `BulkCreateDebitMemosFromInvoiceRequest`
                    if (value.getActualInstance() instanceof BulkCreateDebitMemosFromInvoiceRequest) {
                        JsonElement element = adapterBulkCreateDebitMemosFromInvoiceRequest.toJsonTree((BulkCreateDebitMemosFromInvoiceRequest)value.getActualInstance());
                        elementAdapter.write(out, element);
                        return;
                    }
                    // check if the actual instance is of the type `BulkCreateDebitMemosFromChargeRequest`
                    if (value.getActualInstance() instanceof BulkCreateDebitMemosFromChargeRequest) {
                        JsonElement element = adapterBulkCreateDebitMemosFromChargeRequest.toJsonTree((BulkCreateDebitMemosFromChargeRequest)value.getActualInstance());
                        elementAdapter.write(out, element);
                        return;
                    }
                    throw new IOException("Failed to serialize as the type doesn't match oneOf schemas: BulkCreateDebitMemosFromChargeRequest, BulkCreateDebitMemosFromInvoiceRequest");
                }

                @Override
                public BulkCreateDebitMemosRequest read(JsonReader in) throws IOException {
                    Object deserialized = null;
                    JsonElement jsonElement = elementAdapter.read(in);

                    int match = 0;
                    ArrayList errorMessages = new ArrayList<>();
                    TypeAdapter actualAdapter = elementAdapter;

                    // deserialize BulkCreateDebitMemosFromInvoiceRequest
                    try {
                        // validate the JSON object to see if any exception is thrown
                        BulkCreateDebitMemosFromInvoiceRequest.validateJsonElement(jsonElement);
                        actualAdapter = adapterBulkCreateDebitMemosFromInvoiceRequest;
                        match++;
                        log.log(Level.FINER, "Input data matches schema 'BulkCreateDebitMemosFromInvoiceRequest'");
                    } catch (Exception e) {
                        // deserialization failed, continue
                        errorMessages.add(String.format("Deserialization for BulkCreateDebitMemosFromInvoiceRequest failed with `%s`.", e.getMessage()));
                        log.log(Level.FINER, "Input data does not match schema 'BulkCreateDebitMemosFromInvoiceRequest'", e);
                    }
                    // deserialize BulkCreateDebitMemosFromChargeRequest
                    try {
                        // validate the JSON object to see if any exception is thrown
                        BulkCreateDebitMemosFromChargeRequest.validateJsonElement(jsonElement);
                        actualAdapter = adapterBulkCreateDebitMemosFromChargeRequest;
                        match++;
                        log.log(Level.FINER, "Input data matches schema 'BulkCreateDebitMemosFromChargeRequest'");
                    } catch (Exception e) {
                        // deserialization failed, continue
                        errorMessages.add(String.format("Deserialization for BulkCreateDebitMemosFromChargeRequest failed with `%s`.", e.getMessage()));
                        log.log(Level.FINER, "Input data does not match schema 'BulkCreateDebitMemosFromChargeRequest'", e);
                    }

                    if (match == 1) {
                        BulkCreateDebitMemosRequest ret = new BulkCreateDebitMemosRequest();
                        ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement));
                        return ret;
                    }

                    throw new IOException(String.format("Failed deserialization for BulkCreateDebitMemosRequest: %d classes match result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", match, errorMessages, jsonElement.toString()));
                }
            }.nullSafe();
        }
    }

    // store a list of schema names defined in oneOf
    public static final Map> schemas = new HashMap>();

    public BulkCreateDebitMemosRequest() {
        super("oneOf", Boolean.FALSE);
    }

    public BulkCreateDebitMemosRequest(Object o) {
        super("oneOf", Boolean.FALSE);
        setActualInstance(o);
    }

    static {
        schemas.put("BulkCreateDebitMemosFromInvoiceRequest", BulkCreateDebitMemosFromInvoiceRequest.class);
        schemas.put("BulkCreateDebitMemosFromChargeRequest", BulkCreateDebitMemosFromChargeRequest.class);
    }

    @Override
    public Map> getSchemas() {
        return BulkCreateDebitMemosRequest.schemas;
    }

    /**
     * Set the instance that matches the oneOf child schema, check
     * the instance parameter is valid against the oneOf child schemas:
     * BulkCreateDebitMemosFromChargeRequest, BulkCreateDebitMemosFromInvoiceRequest
     *
     * It could be an instance of the 'oneOf' schemas.
     */
    @Override
    public void setActualInstance(Object instance) {
        if (instance instanceof BulkCreateDebitMemosFromInvoiceRequest) {
            super.setActualInstance(instance);
            return;
        }

        if (instance instanceof BulkCreateDebitMemosFromChargeRequest) {
            super.setActualInstance(instance);
            return;
        }

        throw new RuntimeException("Invalid instance type. Must be BulkCreateDebitMemosFromChargeRequest, BulkCreateDebitMemosFromInvoiceRequest");
    }

    /**
     * Get the actual instance, which can be the following:
     * BulkCreateDebitMemosFromChargeRequest, BulkCreateDebitMemosFromInvoiceRequest
     *
     * @return The actual instance (BulkCreateDebitMemosFromChargeRequest, BulkCreateDebitMemosFromInvoiceRequest)
     */
    @SuppressWarnings("unchecked")
    @Override
    public Object getActualInstance() {
        return super.getActualInstance();
    }

    /**
     * Get the actual instance of `BulkCreateDebitMemosFromInvoiceRequest`. If the actual instance is not `BulkCreateDebitMemosFromInvoiceRequest`,
     * the ClassCastException will be thrown.
     *
     * @return The actual instance of `BulkCreateDebitMemosFromInvoiceRequest`
     * @throws ClassCastException if the instance is not `BulkCreateDebitMemosFromInvoiceRequest`
     */
    public BulkCreateDebitMemosFromInvoiceRequest getBulkCreateDebitMemosFromInvoiceRequest() throws ClassCastException {
        return (BulkCreateDebitMemosFromInvoiceRequest)super.getActualInstance();
    }
    /**
     * Get the actual instance of `BulkCreateDebitMemosFromChargeRequest`. If the actual instance is not `BulkCreateDebitMemosFromChargeRequest`,
     * the ClassCastException will be thrown.
     *
     * @return The actual instance of `BulkCreateDebitMemosFromChargeRequest`
     * @throws ClassCastException if the instance is not `BulkCreateDebitMemosFromChargeRequest`
     */
    public BulkCreateDebitMemosFromChargeRequest getBulkCreateDebitMemosFromChargeRequest() throws ClassCastException {
        return (BulkCreateDebitMemosFromChargeRequest)super.getActualInstance();
    }

    /**
     * Validates the JSON Element and throws an exception if issues found
     *
     * @param jsonElement JSON Element
     * @throws IOException if the JSON Element is invalid with respect to BulkCreateDebitMemosRequest
     */
    public static void validateJsonElement(JsonElement jsonElement) throws IOException {
        // validate oneOf schemas one by one
        int validCount = 0;
        ArrayList errorMessages = new ArrayList<>();
        // validate the json string with BulkCreateDebitMemosFromInvoiceRequest
        try {
            BulkCreateDebitMemosFromInvoiceRequest.validateJsonElement(jsonElement);
            validCount++;
        } catch (Exception e) {
            errorMessages.add(String.format("Deserialization for BulkCreateDebitMemosFromInvoiceRequest failed with `%s`.", e.getMessage()));
            // continue to the next one
        }
        // validate the json string with BulkCreateDebitMemosFromChargeRequest
        try {
            BulkCreateDebitMemosFromChargeRequest.validateJsonElement(jsonElement);
            validCount++;
        } catch (Exception e) {
            errorMessages.add(String.format("Deserialization for BulkCreateDebitMemosFromChargeRequest failed with `%s`.", e.getMessage()));
            // continue to the next one
        }
        if (validCount != 1) {
            throw new IOException(String.format("The JSON string is invalid for BulkCreateDebitMemosRequest with oneOf schemas: BulkCreateDebitMemosFromChargeRequest, BulkCreateDebitMemosFromInvoiceRequest. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString()));
        }
    }

    /**
     * Create an instance of BulkCreateDebitMemosRequest given an JSON string
     *
     * @param jsonString JSON string
     * @return An instance of BulkCreateDebitMemosRequest
     * @throws IOException if the JSON string is invalid with respect to BulkCreateDebitMemosRequest
     */
    public static BulkCreateDebitMemosRequest fromJson(String jsonString) throws IOException {
        return JSON.getGson().fromJson(jsonString, BulkCreateDebitMemosRequest.class);
    }

    /**
     * Convert an instance of BulkCreateDebitMemosRequest to an JSON string
     *
     * @return JSON string
     */
    public String toJson() {
        return JSON.getGson().toJson(this);
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy