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

com.zuora.model.ContactInfo 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.PhoneType;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.zuora.JSON;

/**
 * ContactInfo
 */
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.6.0")
public class ContactInfo {
  public static final String SERIALIZED_NAME_ADDRESS1 = "address1";
  @SerializedName(SERIALIZED_NAME_ADDRESS1)
  private String address1;

  public static final String SERIALIZED_NAME_ADDRESS2 = "address2";
  @SerializedName(SERIALIZED_NAME_ADDRESS2)
  private String address2;

  public static final String SERIALIZED_NAME_CITY = "city";
  @SerializedName(SERIALIZED_NAME_CITY)
  private String city;

  public static final String SERIALIZED_NAME_CONTACT_DESCRIPTION = "contactDescription";
  @SerializedName(SERIALIZED_NAME_CONTACT_DESCRIPTION)
  private String contactDescription;

  public static final String SERIALIZED_NAME_COUNTRY = "country";
  @SerializedName(SERIALIZED_NAME_COUNTRY)
  private String country;

  public static final String SERIALIZED_NAME_COUNTY = "county";
  @SerializedName(SERIALIZED_NAME_COUNTY)
  private String county;

  public static final String SERIALIZED_NAME_CUSTOM_FIELDS = "customFields";
  @SerializedName(SERIALIZED_NAME_CUSTOM_FIELDS)
  private Map customFields;

  public static final String SERIALIZED_NAME_FAX = "fax";
  @SerializedName(SERIALIZED_NAME_FAX)
  private String fax;

  public static final String SERIALIZED_NAME_FIRST_NAME = "firstName";
  @SerializedName(SERIALIZED_NAME_FIRST_NAME)
  private String firstName;

  public static final String SERIALIZED_NAME_HOME_PHONE = "homePhone";
  @SerializedName(SERIALIZED_NAME_HOME_PHONE)
  private String homePhone;

  public static final String SERIALIZED_NAME_LAST_NAME = "lastName";
  @SerializedName(SERIALIZED_NAME_LAST_NAME)
  private String lastName;

  public static final String SERIALIZED_NAME_MOBILE_PHONE = "mobilePhone";
  @SerializedName(SERIALIZED_NAME_MOBILE_PHONE)
  private String mobilePhone;

  public static final String SERIALIZED_NAME_NICKNAME = "nickname";
  @SerializedName(SERIALIZED_NAME_NICKNAME)
  private String nickname;

  public static final String SERIALIZED_NAME_OTHER_PHONE = "otherPhone";
  @SerializedName(SERIALIZED_NAME_OTHER_PHONE)
  private String otherPhone;

  public static final String SERIALIZED_NAME_OTHER_PHONE_TYPE = "otherPhoneType";
  @SerializedName(SERIALIZED_NAME_OTHER_PHONE_TYPE)
  private PhoneType otherPhoneType;

  public static final String SERIALIZED_NAME_PERSONAL_EMAIL = "personalEmail";
  @SerializedName(SERIALIZED_NAME_PERSONAL_EMAIL)
  private String personalEmail;

  public static final String SERIALIZED_NAME_POSTAL_CODE = "postalCode";
  @SerializedName(SERIALIZED_NAME_POSTAL_CODE)
  private String postalCode;

  public static final String SERIALIZED_NAME_STATE = "state";
  @SerializedName(SERIALIZED_NAME_STATE)
  private String state;

  public static final String SERIALIZED_NAME_TAX_REGION = "taxRegion";
  @SerializedName(SERIALIZED_NAME_TAX_REGION)
  private String taxRegion;

  public static final String SERIALIZED_NAME_WORK_EMAIL = "workEmail";
  @SerializedName(SERIALIZED_NAME_WORK_EMAIL)
  private String workEmail;

  public static final String SERIALIZED_NAME_WORK_PHONE = "workPhone";
  @SerializedName(SERIALIZED_NAME_WORK_PHONE)
  private String workPhone;

  public ContactInfo() {
  }

  public ContactInfo address1(String address1) {
    this.address1 = address1;
    return this;
  }

  /**
   * First line of the contact's address. This is often a street address or a business name. 
   * @return address1
   */
  @javax.annotation.Nullable
  public String getAddress1() {
    return address1;
  }

  public void setAddress1(String address1) {
    this.address1 = address1;
  }


  public ContactInfo address2(String address2) {
    this.address2 = address2;
    return this;
  }

  /**
   * Second line of the contact's address. 
   * @return address2
   */
  @javax.annotation.Nullable
  public String getAddress2() {
    return address2;
  }

  public void setAddress2(String address2) {
    this.address2 = address2;
  }


  public ContactInfo city(String city) {
    this.city = city;
    return this;
  }

  /**
   * City of the contact's address. 
   * @return city
   */
  @javax.annotation.Nullable
  public String getCity() {
    return city;
  }

  public void setCity(String city) {
    this.city = city;
  }


  public ContactInfo contactDescription(String contactDescription) {
    this.contactDescription = contactDescription;
    return this;
  }

  /**
   * A description for the contact. 
   * @return contactDescription
   */
  @javax.annotation.Nullable
  public String getContactDescription() {
    return contactDescription;
  }

  public void setContactDescription(String contactDescription) {
    this.contactDescription = contactDescription;
  }


  public ContactInfo country(String country) {
    this.country = country;
    return this;
  }

  /**
   * Country; must be a valid country name or abbreviation. If using [Zuora Tax](https://knowledgecenter.zuora.com/Zuora_Billing/Taxes/A_Zuora_Tax), you must specify a country in the bill-to contact to calculate tax. 
   * @return country
   */
  @javax.annotation.Nullable
  public String getCountry() {
    return country;
  }

  public void setCountry(String country) {
    this.country = country;
  }


  public ContactInfo county(String county) {
    this.county = county;
    return this;
  }

  /**
   * County of the contact's address. 
   * @return county
   */
  @javax.annotation.Nullable
  public String getCounty() {
    return county;
  }

  public void setCounty(String county) {
    this.county = county;
  }


  public ContactInfo customFields(Map customFields) {
    this.customFields = customFields;
    return this;
  }

  public ContactInfo putCustomFieldsItem(String key, Object customFieldsItem) {
    if (this.customFields == null) {
      this.customFields = new HashMap<>();
    }
    this.customFields.put(key, customFieldsItem);
    return this;
  }

  /**
   * Custom fields of the Account object. The name of each custom field has the form <code>*customField*__c</code>. Custom field names are case sensitive. See [Manage Custom Fields](https://knowledgecenter.zuora.com/BB_Introducing_Z_Business/Manage_Custom_Fields) for more information. 
   * @return customFields
   */
  @javax.annotation.Nullable
  public Map getCustomFields() {
    return customFields;
  }

  public void setCustomFields(Map customFields) {
    this.customFields = customFields;
  }


  public ContactInfo fax(String fax) {
    this.fax = fax;
    return this;
  }

  /**
   * Fax number of the contact. 
   * @return fax
   */
  @javax.annotation.Nullable
  public String getFax() {
    return fax;
  }

  public void setFax(String fax) {
    this.fax = fax;
  }


  public ContactInfo firstName(String firstName) {
    this.firstName = firstName;
    return this;
  }

  /**
   * First name of the contact. 
   * @return firstName
   */
  @javax.annotation.Nonnull
  public String getFirstName() {
    return firstName;
  }

  public void setFirstName(String firstName) {
    this.firstName = firstName;
  }


  public ContactInfo homePhone(String homePhone) {
    this.homePhone = homePhone;
    return this;
  }

  /**
   * Home phone number of the contact. 
   * @return homePhone
   */
  @javax.annotation.Nullable
  public String getHomePhone() {
    return homePhone;
  }

  public void setHomePhone(String homePhone) {
    this.homePhone = homePhone;
  }


  public ContactInfo lastName(String lastName) {
    this.lastName = lastName;
    return this;
  }

  /**
   * 
   * @return lastName
   */
  @javax.annotation.Nonnull
  public String getLastName() {
    return lastName;
  }

  public void setLastName(String lastName) {
    this.lastName = lastName;
  }


  public ContactInfo mobilePhone(String mobilePhone) {
    this.mobilePhone = mobilePhone;
    return this;
  }

  /**
   * Mobile phone number of the contact. 
   * @return mobilePhone
   */
  @javax.annotation.Nullable
  public String getMobilePhone() {
    return mobilePhone;
  }

  public void setMobilePhone(String mobilePhone) {
    this.mobilePhone = mobilePhone;
  }


  public ContactInfo nickname(String nickname) {
    this.nickname = nickname;
    return this;
  }

  /**
   * Nickname of the contact. 
   * @return nickname
   */
  @javax.annotation.Nullable
  public String getNickname() {
    return nickname;
  }

  public void setNickname(String nickname) {
    this.nickname = nickname;
  }


  public ContactInfo otherPhone(String otherPhone) {
    this.otherPhone = otherPhone;
    return this;
  }

  /**
   * Additional phone number of the contact. Use the `otherPhoneType` field to specify the type of phone number. 
   * @return otherPhone
   */
  @javax.annotation.Nullable
  public String getOtherPhone() {
    return otherPhone;
  }

  public void setOtherPhone(String otherPhone) {
    this.otherPhone = otherPhone;
  }


  public ContactInfo otherPhoneType(PhoneType otherPhoneType) {
    this.otherPhoneType = otherPhoneType;
    return this;
  }

  /**
   * Get otherPhoneType
   * @return otherPhoneType
   */
  @javax.annotation.Nullable
  public PhoneType getOtherPhoneType() {
    return otherPhoneType;
  }

  public void setOtherPhoneType(PhoneType otherPhoneType) {
    this.otherPhoneType = otherPhoneType;
  }


  public ContactInfo personalEmail(String personalEmail) {
    this.personalEmail = personalEmail;
    return this;
  }

  /**
   * Personal email address of the contact. 
   * @return personalEmail
   */
  @javax.annotation.Nullable
  public String getPersonalEmail() {
    return personalEmail;
  }

  public void setPersonalEmail(String personalEmail) {
    this.personalEmail = personalEmail;
  }


  public ContactInfo postalCode(String postalCode) {
    this.postalCode = postalCode;
    return this;
  }

  /**
   * ZIP code or other postal code of the contact's address. 
   * @return postalCode
   */
  @javax.annotation.Nullable
  public String getPostalCode() {
    return postalCode;
  }

  public void setPostalCode(String postalCode) {
    this.postalCode = postalCode;
  }


  public ContactInfo state(String state) {
    this.state = state;
    return this;
  }

  /**
   * State or province of the contact's address. 
   * @return state
   */
  @javax.annotation.Nullable
  public String getState() {
    return state;
  }

  public void setState(String state) {
    this.state = state;
  }


  public ContactInfo taxRegion(String taxRegion) {
    this.taxRegion = taxRegion;
    return this;
  }

  /**
   * Region defined in your taxation rules. Only applicable if you use Zuora Tax. 
   * @return taxRegion
   */
  @javax.annotation.Nullable
  public String getTaxRegion() {
    return taxRegion;
  }

  public void setTaxRegion(String taxRegion) {
    this.taxRegion = taxRegion;
  }


  public ContactInfo workEmail(String workEmail) {
    this.workEmail = workEmail;
    return this;
  }

  /**
   * Business email address of the contact. 
   * @return workEmail
   */
  @javax.annotation.Nullable
  public String getWorkEmail() {
    return workEmail;
  }

  public void setWorkEmail(String workEmail) {
    this.workEmail = workEmail;
  }


  public ContactInfo workPhone(String workPhone) {
    this.workPhone = workPhone;
    return this;
  }

  /**
   * Business phone number of the contact. 
   * @return workPhone
   */
  @javax.annotation.Nullable
  public String getWorkPhone() {
    return workPhone;
  }

  public void setWorkPhone(String workPhone) {
    this.workPhone = workPhone;
  }

  /**
   * A container for additional, undeclared properties.
   * This is a holder for any undeclared properties as specified with
   * the 'additionalProperties' keyword in the OAS document.
   */
  private Map additionalProperties;

  /**
   * Set the additional (undeclared) property with the specified name and value.
   * If the property does not already exist, create it otherwise replace it.
   *
   * @param key name of the property
   * @param value value of the property
   * @return the ContactInfo instance itself
   */
  public ContactInfo putAdditionalProperty(String key, Object value) {
    if (this.additionalProperties == null) {
        this.additionalProperties = new HashMap();
    }
    this.additionalProperties.put(key, value);
    return this;
  }

  /**
   * Return the additional (undeclared) property.
   *
   * @return a map of objects
   */
  public Map getAdditionalProperties() {
    return additionalProperties;
  }

  /**
   * Return the additional (undeclared) property with the specified name.
   *
   * @param key name of the property
   * @return an object
   */
  public Object getAdditionalProperty(String key) {
    if (this.additionalProperties == null) {
        return null;
    }
    return this.additionalProperties.get(key);
  }


  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    ContactInfo contactInfo = (ContactInfo) o;
    return Objects.equals(this.address1, contactInfo.address1) &&
        Objects.equals(this.address2, contactInfo.address2) &&
        Objects.equals(this.city, contactInfo.city) &&
        Objects.equals(this.contactDescription, contactInfo.contactDescription) &&
        Objects.equals(this.country, contactInfo.country) &&
        Objects.equals(this.county, contactInfo.county) &&
        Objects.equals(this.customFields, contactInfo.customFields) &&
        Objects.equals(this.fax, contactInfo.fax) &&
        Objects.equals(this.firstName, contactInfo.firstName) &&
        Objects.equals(this.homePhone, contactInfo.homePhone) &&
        Objects.equals(this.lastName, contactInfo.lastName) &&
        Objects.equals(this.mobilePhone, contactInfo.mobilePhone) &&
        Objects.equals(this.nickname, contactInfo.nickname) &&
        Objects.equals(this.otherPhone, contactInfo.otherPhone) &&
        Objects.equals(this.otherPhoneType, contactInfo.otherPhoneType) &&
        Objects.equals(this.personalEmail, contactInfo.personalEmail) &&
        Objects.equals(this.postalCode, contactInfo.postalCode) &&
        Objects.equals(this.state, contactInfo.state) &&
        Objects.equals(this.taxRegion, contactInfo.taxRegion) &&
        Objects.equals(this.workEmail, contactInfo.workEmail) &&
        Objects.equals(this.workPhone, contactInfo.workPhone)&&
        Objects.equals(this.additionalProperties, contactInfo.additionalProperties);
  }

  @Override
  public int hashCode() {
    return Objects.hash(address1, address2, city, contactDescription, country, county, customFields, fax, firstName, homePhone, lastName, mobilePhone, nickname, otherPhone, otherPhoneType, personalEmail, postalCode, state, taxRegion, workEmail, workPhone, additionalProperties);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class ContactInfo {\n");
    sb.append("    address1: ").append(toIndentedString(address1)).append("\n");
    sb.append("    address2: ").append(toIndentedString(address2)).append("\n");
    sb.append("    city: ").append(toIndentedString(city)).append("\n");
    sb.append("    contactDescription: ").append(toIndentedString(contactDescription)).append("\n");
    sb.append("    country: ").append(toIndentedString(country)).append("\n");
    sb.append("    county: ").append(toIndentedString(county)).append("\n");
    sb.append("    customFields: ").append(toIndentedString(customFields)).append("\n");
    sb.append("    fax: ").append(toIndentedString(fax)).append("\n");
    sb.append("    firstName: ").append(toIndentedString(firstName)).append("\n");
    sb.append("    homePhone: ").append(toIndentedString(homePhone)).append("\n");
    sb.append("    lastName: ").append(toIndentedString(lastName)).append("\n");
    sb.append("    mobilePhone: ").append(toIndentedString(mobilePhone)).append("\n");
    sb.append("    nickname: ").append(toIndentedString(nickname)).append("\n");
    sb.append("    otherPhone: ").append(toIndentedString(otherPhone)).append("\n");
    sb.append("    otherPhoneType: ").append(toIndentedString(otherPhoneType)).append("\n");
    sb.append("    personalEmail: ").append(toIndentedString(personalEmail)).append("\n");
    sb.append("    postalCode: ").append(toIndentedString(postalCode)).append("\n");
    sb.append("    state: ").append(toIndentedString(state)).append("\n");
    sb.append("    taxRegion: ").append(toIndentedString(taxRegion)).append("\n");
    sb.append("    workEmail: ").append(toIndentedString(workEmail)).append("\n");
    sb.append("    workPhone: ").append(toIndentedString(workPhone)).append("\n");
    sb.append("    additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n");
    sb.append("}");
    return sb.toString();
  }

  /**
   * Convert the given object to string with each line indented by 4 spaces
   * (except the first line).
   */
  private String toIndentedString(Object o) {
    if (o == null) {
      return "null";
    }
    return o.toString().replace("\n", "\n    ");
  }


  public static HashSet openapiFields;
  public static HashSet openapiRequiredFields;

  static {
    // a set of all properties/fields (JSON key names)
    openapiFields = new HashSet();
    openapiFields.add("address1");
    openapiFields.add("address2");
    openapiFields.add("city");
    openapiFields.add("contactDescription");
    openapiFields.add("country");
    openapiFields.add("county");
    openapiFields.add("customFields");
    openapiFields.add("fax");
    openapiFields.add("firstName");
    openapiFields.add("homePhone");
    openapiFields.add("lastName");
    openapiFields.add("mobilePhone");
    openapiFields.add("nickname");
    openapiFields.add("otherPhone");
    openapiFields.add("otherPhoneType");
    openapiFields.add("personalEmail");
    openapiFields.add("postalCode");
    openapiFields.add("state");
    openapiFields.add("taxRegion");
    openapiFields.add("workEmail");
    openapiFields.add("workPhone");

    // a set of required properties/fields (JSON key names)
    openapiRequiredFields = new HashSet();
    openapiRequiredFields.add("firstName");
    openapiRequiredFields.add("lastName");
  }

  /**
   * 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 ContactInfo
   */
  public static void validateJsonElement(JsonElement jsonElement) throws IOException {
      if (jsonElement == null) {
        if (!ContactInfo.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null
          throw new IllegalArgumentException(String.format("The required field(s) %s in ContactInfo is not found in the empty JSON string", ContactInfo.openapiRequiredFields.toString()));
        }
      }

      // check to make sure all required properties/fields are present in the JSON string
      for (String requiredField : ContactInfo.openapiRequiredFields) {
        if (jsonElement.getAsJsonObject().get(requiredField) == null) {
          throw new IllegalArgumentException(String.format("The required field `%s` is not found in the JSON string: %s", requiredField, jsonElement.toString()));
        }
      }
        JsonObject jsonObj = jsonElement.getAsJsonObject();
      if ((jsonObj.get("address1") != null && !jsonObj.get("address1").isJsonNull()) && !jsonObj.get("address1").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `address1` to be a primitive type in the JSON string but got `%s`", jsonObj.get("address1").toString()));
      }
      if ((jsonObj.get("address2") != null && !jsonObj.get("address2").isJsonNull()) && !jsonObj.get("address2").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `address2` to be a primitive type in the JSON string but got `%s`", jsonObj.get("address2").toString()));
      }
      if ((jsonObj.get("city") != null && !jsonObj.get("city").isJsonNull()) && !jsonObj.get("city").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `city` to be a primitive type in the JSON string but got `%s`", jsonObj.get("city").toString()));
      }
      if ((jsonObj.get("contactDescription") != null && !jsonObj.get("contactDescription").isJsonNull()) && !jsonObj.get("contactDescription").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `contactDescription` to be a primitive type in the JSON string but got `%s`", jsonObj.get("contactDescription").toString()));
      }
      if ((jsonObj.get("country") != null && !jsonObj.get("country").isJsonNull()) && !jsonObj.get("country").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `country` to be a primitive type in the JSON string but got `%s`", jsonObj.get("country").toString()));
      }
      if ((jsonObj.get("county") != null && !jsonObj.get("county").isJsonNull()) && !jsonObj.get("county").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `county` to be a primitive type in the JSON string but got `%s`", jsonObj.get("county").toString()));
      }
      if ((jsonObj.get("fax") != null && !jsonObj.get("fax").isJsonNull()) && !jsonObj.get("fax").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `fax` to be a primitive type in the JSON string but got `%s`", jsonObj.get("fax").toString()));
      }
      if (!jsonObj.get("firstName").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `firstName` to be a primitive type in the JSON string but got `%s`", jsonObj.get("firstName").toString()));
      }
      if ((jsonObj.get("homePhone") != null && !jsonObj.get("homePhone").isJsonNull()) && !jsonObj.get("homePhone").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `homePhone` to be a primitive type in the JSON string but got `%s`", jsonObj.get("homePhone").toString()));
      }
      if (!jsonObj.get("lastName").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `lastName` to be a primitive type in the JSON string but got `%s`", jsonObj.get("lastName").toString()));
      }
      if ((jsonObj.get("mobilePhone") != null && !jsonObj.get("mobilePhone").isJsonNull()) && !jsonObj.get("mobilePhone").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `mobilePhone` to be a primitive type in the JSON string but got `%s`", jsonObj.get("mobilePhone").toString()));
      }
      if ((jsonObj.get("nickname") != null && !jsonObj.get("nickname").isJsonNull()) && !jsonObj.get("nickname").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `nickname` to be a primitive type in the JSON string but got `%s`", jsonObj.get("nickname").toString()));
      }
      if ((jsonObj.get("otherPhone") != null && !jsonObj.get("otherPhone").isJsonNull()) && !jsonObj.get("otherPhone").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `otherPhone` to be a primitive type in the JSON string but got `%s`", jsonObj.get("otherPhone").toString()));
      }
      if ((jsonObj.get("otherPhoneType") != null && !jsonObj.get("otherPhoneType").isJsonNull()) && !jsonObj.get("otherPhoneType").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `otherPhoneType` to be a primitive type in the JSON string but got `%s`", jsonObj.get("otherPhoneType").toString()));
      }
      // validate the optional field `otherPhoneType`
      if (jsonObj.get("otherPhoneType") != null && !jsonObj.get("otherPhoneType").isJsonNull()) {
        PhoneType.validateJsonElement(jsonObj.get("otherPhoneType"));
      }
      if ((jsonObj.get("personalEmail") != null && !jsonObj.get("personalEmail").isJsonNull()) && !jsonObj.get("personalEmail").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `personalEmail` to be a primitive type in the JSON string but got `%s`", jsonObj.get("personalEmail").toString()));
      }
      if ((jsonObj.get("postalCode") != null && !jsonObj.get("postalCode").isJsonNull()) && !jsonObj.get("postalCode").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `postalCode` to be a primitive type in the JSON string but got `%s`", jsonObj.get("postalCode").toString()));
      }
      if ((jsonObj.get("state") != null && !jsonObj.get("state").isJsonNull()) && !jsonObj.get("state").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `state` to be a primitive type in the JSON string but got `%s`", jsonObj.get("state").toString()));
      }
      if ((jsonObj.get("taxRegion") != null && !jsonObj.get("taxRegion").isJsonNull()) && !jsonObj.get("taxRegion").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `taxRegion` to be a primitive type in the JSON string but got `%s`", jsonObj.get("taxRegion").toString()));
      }
      if ((jsonObj.get("workEmail") != null && !jsonObj.get("workEmail").isJsonNull()) && !jsonObj.get("workEmail").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `workEmail` to be a primitive type in the JSON string but got `%s`", jsonObj.get("workEmail").toString()));
      }
      if ((jsonObj.get("workPhone") != null && !jsonObj.get("workPhone").isJsonNull()) && !jsonObj.get("workPhone").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `workPhone` to be a primitive type in the JSON string but got `%s`", jsonObj.get("workPhone").toString()));
      }
  }

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

       return (TypeAdapter) new TypeAdapter() {
           @Override
           public void write(JsonWriter out, ContactInfo value) throws IOException {
             JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
             obj.remove("additionalProperties");

             // support null values
             out.beginObject();
             Iterator iterator = obj.entrySet().iterator();
             while(iterator.hasNext()) {
                 Map.Entry e = (Map.Entry) iterator.next();
                 out.name((String)e.getKey());
                 elementAdapter.write(out, e.getValue());
             }

             // end

             // serialize additional properties
             if (value.getAdditionalProperties() != null) {
               // support null values
               boolean oldSerializeNulls = out.getSerializeNulls();
               out.setSerializeNulls(true); //force serialize
               // end
               for (Map.Entry entry : value.getAdditionalProperties().entrySet()) {
                 if (entry.getValue() instanceof String)
                   obj.addProperty(entry.getKey(), (String) entry.getValue());
                 else if (entry.getValue() instanceof Number)
                   obj.addProperty(entry.getKey(), (Number) entry.getValue());
                 else if (entry.getValue() instanceof Boolean)
                   obj.addProperty(entry.getKey(), (Boolean) entry.getValue());
                 else if (entry.getValue() instanceof Character)
                   obj.addProperty(entry.getKey(), (Character) entry.getValue());
                 else if (entry.getValue() == null)
                    obj.add(entry.getKey(), null);
                 else {
                   JsonElement jsonElement = gson.toJsonTree(entry.getValue());
                   if (jsonElement.isJsonArray()) {
                     obj.add(entry.getKey(), jsonElement.getAsJsonArray());
                   } else {
                     obj.add(entry.getKey(), jsonElement.getAsJsonObject());
                   }
                 }
                 out.name((String)entry.getKey());
                 elementAdapter.write(out, obj.get(entry.getKey()));
               }
               out.setSerializeNulls(oldSerializeNulls); //restore
             }
             out.endObject();

           }

           @Override
           public ContactInfo read(JsonReader in) throws IOException {
             JsonElement jsonElement = elementAdapter.read(in);
             validateJsonElement(jsonElement);
             JsonObject jsonObj = jsonElement.getAsJsonObject();
             // store additional fields in the deserialized instance
             ContactInfo instance = thisAdapter.fromJsonTree(jsonObj);
             for (Map.Entry entry : jsonObj.entrySet()) {
               if (!openapiFields.contains(entry.getKey())) {
                 if (entry.getValue().isJsonPrimitive()) { // primitive type
                   if (entry.getValue().getAsJsonPrimitive().isString())
                     instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsString());
                   else if (entry.getValue().getAsJsonPrimitive().isNumber())
                     instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsNumber());
                   else if (entry.getValue().getAsJsonPrimitive().isBoolean())
                     instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsBoolean());
                   else
                     throw new IllegalArgumentException(String.format("The field `%s` has unknown primitive type. Value: %s", entry.getKey(), entry.getValue().toString()));
                 } else if (entry.getValue().isJsonArray()) {
                     instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), List.class));
                 } else { // JSON object
                     instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), HashMap.class));
                 }
               }
             }
             return instance;
           }

       }.nullSafe();
    }
  }

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

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





© 2015 - 2025 Weber Informatics LLC | Privacy Policy