com.messente.api.OmnimessageMessagesInner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of messente-api Show documentation
Show all versions of messente-api Show documentation
Messente API - Connecting Services to People
The newest version!
/*
* Messente API
* [Messente](https://messente.com) is a global provider of messaging and user verification services. * Send and receive SMS, Viber, WhatsApp and Telegram messages. * Manage contacts and groups. * Fetch detailed info about phone numbers. * Blacklist phone numbers to make sure you're not sending any unwanted messages. Messente builds [tools](https://messente.com/documentation) to help organizations connect their services to people anywhere in the world.
*
* The version of the OpenAPI document: 2.0.0
* 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.messente.api;
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.messente.api.SMS;
import com.messente.api.Telegram;
import com.messente.api.Viber;
import com.messente.api.ViberVideo;
import com.messente.api.WhatsApp;
import com.messente.api.WhatsAppTemplate;
import java.io.IOException;
import java.util.Arrays;
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.messente.JSON;
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.6.0")
public class OmnimessageMessagesInner extends AbstractOpenApiSchema {
private static final Logger log = Logger.getLogger(OmnimessageMessagesInner.class.getName());
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public TypeAdapter create(Gson gson, TypeToken type) {
if (!OmnimessageMessagesInner.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'OmnimessageMessagesInner' and its subtypes
}
final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter adapterViber = gson.getDelegateAdapter(this, TypeToken.get(Viber.class));
final TypeAdapter adapterSMS = gson.getDelegateAdapter(this, TypeToken.get(SMS.class));
final TypeAdapter adapterWhatsApp = gson.getDelegateAdapter(this, TypeToken.get(WhatsApp.class));
final TypeAdapter adapterTelegram = gson.getDelegateAdapter(this, TypeToken.get(Telegram.class));
return (TypeAdapter) new TypeAdapter() {
@Override
public void write(JsonWriter out, OmnimessageMessagesInner value) throws IOException {
if (value == null || value.getActualInstance() == null) {
elementAdapter.write(out, null);
return;
}
// check if the actual instance is of the type `Viber`
if (value.getActualInstance() instanceof Viber) {
JsonElement element = adapterViber.toJsonTree((Viber)value.getActualInstance());
elementAdapter.write(out, element);
return;
}
// check if the actual instance is of the type `SMS`
if (value.getActualInstance() instanceof SMS) {
JsonElement element = adapterSMS.toJsonTree((SMS)value.getActualInstance());
elementAdapter.write(out, element);
return;
}
// check if the actual instance is of the type `WhatsApp`
if (value.getActualInstance() instanceof WhatsApp) {
JsonElement element = adapterWhatsApp.toJsonTree((WhatsApp)value.getActualInstance());
elementAdapter.write(out, element);
return;
}
// check if the actual instance is of the type `Telegram`
if (value.getActualInstance() instanceof Telegram) {
JsonElement element = adapterTelegram.toJsonTree((Telegram)value.getActualInstance());
elementAdapter.write(out, element);
return;
}
throw new IOException("Failed to serialize as the type doesn't match oneOf schemas: SMS, Telegram, Viber, WhatsApp");
}
@Override
public OmnimessageMessagesInner read(JsonReader in) throws IOException {
Object deserialized = null;
JsonElement jsonElement = elementAdapter.read(in);
int match = 0;
ArrayList errorMessages = new ArrayList<>();
TypeAdapter actualAdapter = elementAdapter;
// deserialize Viber
try {
// validate the JSON object to see if any exception is thrown
Viber.validateJsonElement(jsonElement);
actualAdapter = adapterViber;
match++;
log.log(Level.FINER, "Input data matches schema 'Viber'");
} catch (Exception e) {
// deserialization failed, continue
errorMessages.add(String.format("Deserialization for Viber failed with `%s`.", e.getMessage()));
log.log(Level.FINER, "Input data does not match schema 'Viber'", e);
}
// deserialize SMS
try {
// validate the JSON object to see if any exception is thrown
SMS.validateJsonElement(jsonElement);
actualAdapter = adapterSMS;
match++;
log.log(Level.FINER, "Input data matches schema 'SMS'");
} catch (Exception e) {
// deserialization failed, continue
errorMessages.add(String.format("Deserialization for SMS failed with `%s`.", e.getMessage()));
log.log(Level.FINER, "Input data does not match schema 'SMS'", e);
}
// deserialize WhatsApp
try {
// validate the JSON object to see if any exception is thrown
WhatsApp.validateJsonElement(jsonElement);
actualAdapter = adapterWhatsApp;
match++;
log.log(Level.FINER, "Input data matches schema 'WhatsApp'");
} catch (Exception e) {
// deserialization failed, continue
errorMessages.add(String.format("Deserialization for WhatsApp failed with `%s`.", e.getMessage()));
log.log(Level.FINER, "Input data does not match schema 'WhatsApp'", e);
}
// deserialize Telegram
try {
// validate the JSON object to see if any exception is thrown
Telegram.validateJsonElement(jsonElement);
actualAdapter = adapterTelegram;
match++;
log.log(Level.FINER, "Input data matches schema 'Telegram'");
} catch (Exception e) {
// deserialization failed, continue
errorMessages.add(String.format("Deserialization for Telegram failed with `%s`.", e.getMessage()));
log.log(Level.FINER, "Input data does not match schema 'Telegram'", e);
}
if (match == 1) {
OmnimessageMessagesInner ret = new OmnimessageMessagesInner();
ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement));
return ret;
}
throw new IOException(String.format("Failed deserialization for OmnimessageMessagesInner: %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 OmnimessageMessagesInner() {
super("oneOf", Boolean.FALSE);
}
public OmnimessageMessagesInner(Object o) {
super("oneOf", Boolean.FALSE);
setActualInstance(o);
}
static {
schemas.put("Viber", Viber.class);
schemas.put("SMS", SMS.class);
schemas.put("WhatsApp", WhatsApp.class);
schemas.put("Telegram", Telegram.class);
}
@Override
public Map> getSchemas() {
return OmnimessageMessagesInner.schemas;
}
/**
* Set the instance that matches the oneOf child schema, check
* the instance parameter is valid against the oneOf child schemas:
* SMS, Telegram, Viber, WhatsApp
*
* It could be an instance of the 'oneOf' schemas.
*/
@Override
public void setActualInstance(Object instance) {
if (instance instanceof Viber) {
super.setActualInstance(instance);
return;
}
if (instance instanceof SMS) {
super.setActualInstance(instance);
return;
}
if (instance instanceof WhatsApp) {
super.setActualInstance(instance);
return;
}
if (instance instanceof Telegram) {
super.setActualInstance(instance);
return;
}
throw new RuntimeException("Invalid instance type. Must be SMS, Telegram, Viber, WhatsApp");
}
/**
* Get the actual instance, which can be the following:
* SMS, Telegram, Viber, WhatsApp
*
* @return The actual instance (SMS, Telegram, Viber, WhatsApp)
*/
@SuppressWarnings("unchecked")
@Override
public Object getActualInstance() {
return super.getActualInstance();
}
/**
* Get the actual instance of `Viber`. If the actual instance is not `Viber`,
* the ClassCastException will be thrown.
*
* @return The actual instance of `Viber`
* @throws ClassCastException if the instance is not `Viber`
*/
public Viber getViber() throws ClassCastException {
return (Viber)super.getActualInstance();
}
/**
* Get the actual instance of `SMS`. If the actual instance is not `SMS`,
* the ClassCastException will be thrown.
*
* @return The actual instance of `SMS`
* @throws ClassCastException if the instance is not `SMS`
*/
public SMS getSMS() throws ClassCastException {
return (SMS)super.getActualInstance();
}
/**
* Get the actual instance of `WhatsApp`. If the actual instance is not `WhatsApp`,
* the ClassCastException will be thrown.
*
* @return The actual instance of `WhatsApp`
* @throws ClassCastException if the instance is not `WhatsApp`
*/
public WhatsApp getWhatsApp() throws ClassCastException {
return (WhatsApp)super.getActualInstance();
}
/**
* Get the actual instance of `Telegram`. If the actual instance is not `Telegram`,
* the ClassCastException will be thrown.
*
* @return The actual instance of `Telegram`
* @throws ClassCastException if the instance is not `Telegram`
*/
public Telegram getTelegram() throws ClassCastException {
return (Telegram)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 OmnimessageMessagesInner
*/
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 Viber
try {
Viber.validateJsonElement(jsonElement);
validCount++;
} catch (Exception e) {
errorMessages.add(String.format("Deserialization for Viber failed with `%s`.", e.getMessage()));
// continue to the next one
}
// validate the json string with SMS
try {
SMS.validateJsonElement(jsonElement);
validCount++;
} catch (Exception e) {
errorMessages.add(String.format("Deserialization for SMS failed with `%s`.", e.getMessage()));
// continue to the next one
}
// validate the json string with WhatsApp
try {
WhatsApp.validateJsonElement(jsonElement);
validCount++;
} catch (Exception e) {
errorMessages.add(String.format("Deserialization for WhatsApp failed with `%s`.", e.getMessage()));
// continue to the next one
}
// validate the json string with Telegram
try {
Telegram.validateJsonElement(jsonElement);
validCount++;
} catch (Exception e) {
errorMessages.add(String.format("Deserialization for Telegram failed with `%s`.", e.getMessage()));
// continue to the next one
}
if (validCount != 1) {
throw new IOException(String.format("The JSON string is invalid for OmnimessageMessagesInner with oneOf schemas: SMS, Telegram, Viber, WhatsApp. %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 OmnimessageMessagesInner given an JSON string
*
* @param jsonString JSON string
* @return An instance of OmnimessageMessagesInner
* @throws IOException if the JSON string is invalid with respect to OmnimessageMessagesInner
*/
public static OmnimessageMessagesInner fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, OmnimessageMessagesInner.class);
}
/**
* Convert an instance of OmnimessageMessagesInner to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}