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

com.zuora.model.SubscriptionRatePlan 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.GetSubscriptionRatePlanChargesWithAllSegments;
import com.zuora.model.SubscriptionProductFeature;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

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;

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

  public static final String SERIALIZED_NAME_SUBSCRIPTION_RATE_PLAN_NUMBER = "subscriptionRatePlanNumber";
  @SerializedName(SERIALIZED_NAME_SUBSCRIPTION_RATE_PLAN_NUMBER)
  private String subscriptionRatePlanNumber;

  public static final String SERIALIZED_NAME_IS_FROM_EXTERNAL_CATALOG = "isFromExternalCatalog";
  @SerializedName(SERIALIZED_NAME_IS_FROM_EXTERNAL_CATALOG)
  private Boolean isFromExternalCatalog;

  /**
   * The last amendment on the rate plan.    **Note:** If a subscription is created through an order, this field is only available if multiple orders are created on the subscription.   Possible Values:   * `Add`   * `Update`   * `Remove` 
   */
  @JsonAdapter(LastChangeTypeEnum.Adapter.class)
  public enum LastChangeTypeEnum {
    ADD("Add"),
    
    UPDATE("Update"),
    
    REMOVE("Remove");

    private String value;

    LastChangeTypeEnum(String value) {
      this.value = value;
    }

    public String getValue() {
      return value;
    }

    @Override
    public String toString() {
      return String.valueOf(value);
    }

    public static LastChangeTypeEnum fromValue(String value) {
      for (LastChangeTypeEnum b : LastChangeTypeEnum.values()) {
        if (b.value.equals(value)) {
          return b;
        }
      }
      throw new IllegalArgumentException("Unexpected value '" + value + "'");
    }

    public static class Adapter extends TypeAdapter {
      @Override
      public void write(final JsonWriter jsonWriter, final LastChangeTypeEnum enumeration) throws IOException {
        jsonWriter.value(enumeration.getValue());
      }

      @Override
      public LastChangeTypeEnum read(final JsonReader jsonReader) throws IOException {
        String value =  jsonReader.nextString();
        return LastChangeTypeEnum.fromValue(value);
      }
    }

    public static void validateJsonElement(JsonElement jsonElement) throws IOException {
      String value = jsonElement.getAsString();
      LastChangeTypeEnum.fromValue(value);
    }
  }

  public static final String SERIALIZED_NAME_LAST_CHANGE_TYPE = "lastChangeType";
  @SerializedName(SERIALIZED_NAME_LAST_CHANGE_TYPE)
  private LastChangeTypeEnum lastChangeType;

  public static final String SERIALIZED_NAME_PRODUCT_ID = "productId";
  @SerializedName(SERIALIZED_NAME_PRODUCT_ID)
  private String productId;

  public static final String SERIALIZED_NAME_PRODUCT_NAME = "productName";
  @SerializedName(SERIALIZED_NAME_PRODUCT_NAME)
  private String productName;

  public static final String SERIALIZED_NAME_PRODUCT_SKU = "productSku";
  @SerializedName(SERIALIZED_NAME_PRODUCT_SKU)
  private String productSku;

  public static final String SERIALIZED_NAME_PRODUCT_RATE_PLAN_ID = "productRatePlanId";
  @SerializedName(SERIALIZED_NAME_PRODUCT_RATE_PLAN_ID)
  private String productRatePlanId;

  public static final String SERIALIZED_NAME_PRODUCT_RATE_PLAN_NUMBER = "productRatePlanNumber";
  @SerializedName(SERIALIZED_NAME_PRODUCT_RATE_PLAN_NUMBER)
  private String productRatePlanNumber;

  public static final String SERIALIZED_NAME_RATE_PLAN_NAME = "ratePlanName";
  @SerializedName(SERIALIZED_NAME_RATE_PLAN_NAME)
  private String ratePlanName;

  public static final String SERIALIZED_NAME_SUBSCRIPTION_PRODUCT_FEATURES = "subscriptionProductFeatures";
  @SerializedName(SERIALIZED_NAME_SUBSCRIPTION_PRODUCT_FEATURES)
  private List subscriptionProductFeatures;

  public static final String SERIALIZED_NAME_EXTERNALLY_MANAGED_PLAN_ID = "externallyManagedPlanId";
  @SerializedName(SERIALIZED_NAME_EXTERNALLY_MANAGED_PLAN_ID)
  private String externallyManagedPlanId;

  public static final String SERIALIZED_NAME_CONTRACTED_MRR = "contractedMrr";
  @SerializedName(SERIALIZED_NAME_CONTRACTED_MRR)
  private BigDecimal contractedMrr;

  public static final String SERIALIZED_NAME_CONTRACTED_NET_MRR = "contractedNetMrr";
  @SerializedName(SERIALIZED_NAME_CONTRACTED_NET_MRR)
  private BigDecimal contractedNetMrr;

  public static final String SERIALIZED_NAME_AS_OF_DAY_GROSS_MRR = "asOfDayGrossMrr";
  @SerializedName(SERIALIZED_NAME_AS_OF_DAY_GROSS_MRR)
  private BigDecimal asOfDayGrossMrr;

  public static final String SERIALIZED_NAME_AS_OF_DAY_NET_MRR = "asOfDayNetMrr";
  @SerializedName(SERIALIZED_NAME_AS_OF_DAY_NET_MRR)
  private BigDecimal asOfDayNetMrr;

  public static final String SERIALIZED_NAME_RATE_PLAN_CHARGES = "ratePlanCharges";
  @SerializedName(SERIALIZED_NAME_RATE_PLAN_CHARGES)
  private List ratePlanCharges;

  public SubscriptionRatePlan() {
  }

  public SubscriptionRatePlan id(String id) {
    this.id = id;
    return this;
  }

  /**
   * Rate plan ID. 
   * @return id
   */
  @javax.annotation.Nullable
  public String getId() {
    return id;
  }

  public void setId(String id) {
    this.id = id;
  }


  public SubscriptionRatePlan subscriptionRatePlanNumber(String subscriptionRatePlanNumber) {
    this.subscriptionRatePlanNumber = subscriptionRatePlanNumber;
    return this;
  }

  /**
   * Get subscriptionRatePlanNumber
   * @return subscriptionRatePlanNumber
   */
  @javax.annotation.Nullable
  public String getSubscriptionRatePlanNumber() {
    return subscriptionRatePlanNumber;
  }

  public void setSubscriptionRatePlanNumber(String subscriptionRatePlanNumber) {
    this.subscriptionRatePlanNumber = subscriptionRatePlanNumber;
  }


  public SubscriptionRatePlan isFromExternalCatalog(Boolean isFromExternalCatalog) {
    this.isFromExternalCatalog = isFromExternalCatalog;
    return this;
  }

  /**
   * Get isFromExternalCatalog
   * @return isFromExternalCatalog
   */
  @javax.annotation.Nullable
  public Boolean getIsFromExternalCatalog() {
    return isFromExternalCatalog;
  }

  public void setIsFromExternalCatalog(Boolean isFromExternalCatalog) {
    this.isFromExternalCatalog = isFromExternalCatalog;
  }


  public SubscriptionRatePlan lastChangeType(LastChangeTypeEnum lastChangeType) {
    this.lastChangeType = lastChangeType;
    return this;
  }

  /**
   * The last amendment on the rate plan.    **Note:** If a subscription is created through an order, this field is only available if multiple orders are created on the subscription.   Possible Values:   * `Add`   * `Update`   * `Remove` 
   * @return lastChangeType
   */
  @javax.annotation.Nullable
  public LastChangeTypeEnum getLastChangeType() {
    return lastChangeType;
  }

  public void setLastChangeType(LastChangeTypeEnum lastChangeType) {
    this.lastChangeType = lastChangeType;
  }


  public SubscriptionRatePlan productId(String productId) {
    this.productId = productId;
    return this;
  }

  /**
   * Get productId
   * @return productId
   */
  @javax.annotation.Nullable
  public String getProductId() {
    return productId;
  }

  public void setProductId(String productId) {
    this.productId = productId;
  }


  public SubscriptionRatePlan productName(String productName) {
    this.productName = productName;
    return this;
  }

  /**
   * Get productName
   * @return productName
   */
  @javax.annotation.Nullable
  public String getProductName() {
    return productName;
  }

  public void setProductName(String productName) {
    this.productName = productName;
  }


  public SubscriptionRatePlan productSku(String productSku) {
    this.productSku = productSku;
    return this;
  }

  /**
   * The unique SKU for the product.
   * @return productSku
   */
  @javax.annotation.Nullable
  public String getProductSku() {
    return productSku;
  }

  public void setProductSku(String productSku) {
    this.productSku = productSku;
  }


  public SubscriptionRatePlan productRatePlanId(String productRatePlanId) {
    this.productRatePlanId = productRatePlanId;
    return this;
  }

  /**
   * Get productRatePlanId
   * @return productRatePlanId
   */
  @javax.annotation.Nullable
  public String getProductRatePlanId() {
    return productRatePlanId;
  }

  public void setProductRatePlanId(String productRatePlanId) {
    this.productRatePlanId = productRatePlanId;
  }


  public SubscriptionRatePlan productRatePlanNumber(String productRatePlanNumber) {
    this.productRatePlanNumber = productRatePlanNumber;
    return this;
  }

  /**
   * Get productRatePlanNumber
   * @return productRatePlanNumber
   */
  @javax.annotation.Nullable
  public String getProductRatePlanNumber() {
    return productRatePlanNumber;
  }

  public void setProductRatePlanNumber(String productRatePlanNumber) {
    this.productRatePlanNumber = productRatePlanNumber;
  }


  public SubscriptionRatePlan ratePlanName(String ratePlanName) {
    this.ratePlanName = ratePlanName;
    return this;
  }

  /**
   * Name of the rate plan.
   * @return ratePlanName
   */
  @javax.annotation.Nullable
  public String getRatePlanName() {
    return ratePlanName;
  }

  public void setRatePlanName(String ratePlanName) {
    this.ratePlanName = ratePlanName;
  }


  public SubscriptionRatePlan subscriptionProductFeatures(List subscriptionProductFeatures) {
    this.subscriptionProductFeatures = subscriptionProductFeatures;
    return this;
  }

  public SubscriptionRatePlan addSubscriptionProductFeaturesItem(SubscriptionProductFeature subscriptionProductFeaturesItem) {
    if (this.subscriptionProductFeatures == null) {
      this.subscriptionProductFeatures = new ArrayList<>();
    }
    this.subscriptionProductFeatures.add(subscriptionProductFeaturesItem);
    return this;
  }

  /**
   * Container for one or more features.   Only available when the following settings are enabled:  * The Entitlements feature in your tenant.  * The Enable Feature Specification in Product and Subscriptions setting in Zuora Billing Settings
   * @return subscriptionProductFeatures
   */
  @javax.annotation.Nullable
  public List getSubscriptionProductFeatures() {
    return subscriptionProductFeatures;
  }

  public void setSubscriptionProductFeatures(List subscriptionProductFeatures) {
    this.subscriptionProductFeatures = subscriptionProductFeatures;
  }


  public SubscriptionRatePlan externallyManagedPlanId(String externallyManagedPlanId) {
    this.externallyManagedPlanId = externallyManagedPlanId;
    return this;
  }

  /**
   * Indicates the unique identifier for the rate plan purchased on a third-party store. This field is used to represent a subscription rate plan created through third-party stores. 
   * @return externallyManagedPlanId
   */
  @javax.annotation.Nullable
  public String getExternallyManagedPlanId() {
    return externallyManagedPlanId;
  }

  public void setExternallyManagedPlanId(String externallyManagedPlanId) {
    this.externallyManagedPlanId = externallyManagedPlanId;
  }


  public SubscriptionRatePlan contractedMrr(BigDecimal contractedMrr) {
    this.contractedMrr = contractedMrr;
    return this;
  }

  /**
   * Monthly recurring revenue of the subscription rate plan exclusive of all the discounts applicable. 
   * @return contractedMrr
   */
  @javax.annotation.Nullable
  public BigDecimal getContractedMrr() {
    return contractedMrr;
  }

  public void setContractedMrr(BigDecimal contractedMrr) {
    this.contractedMrr = contractedMrr;
  }


  public SubscriptionRatePlan contractedNetMrr(BigDecimal contractedNetMrr) {
    this.contractedNetMrr = contractedNetMrr;
    return this;
  }

  /**
   * Monthly recurring revenue of the subscription rate plan inclusive of all the discounts applicable, including the fixed-amount discounts and percentage discounts. 
   * @return contractedNetMrr
   */
  @javax.annotation.Nullable
  public BigDecimal getContractedNetMrr() {
    return contractedNetMrr;
  }

  public void setContractedNetMrr(BigDecimal contractedNetMrr) {
    this.contractedNetMrr = contractedNetMrr;
  }


  public SubscriptionRatePlan asOfDayGrossMrr(BigDecimal asOfDayGrossMrr) {
    this.asOfDayGrossMrr = asOfDayGrossMrr;
    return this;
  }

  /**
   * Monthly recurring revenue of the subscription rate plan exclusive of any discounts applicable as of specified day. 
   * @return asOfDayGrossMrr
   */
  @javax.annotation.Nullable
  public BigDecimal getAsOfDayGrossMrr() {
    return asOfDayGrossMrr;
  }

  public void setAsOfDayGrossMrr(BigDecimal asOfDayGrossMrr) {
    this.asOfDayGrossMrr = asOfDayGrossMrr;
  }


  public SubscriptionRatePlan asOfDayNetMrr(BigDecimal asOfDayNetMrr) {
    this.asOfDayNetMrr = asOfDayNetMrr;
    return this;
  }

  /**
   * Monthly recurring revenue of the subscription rate plan inclusive of all the discounts applicable, including the fixed-amount discounts and percentage discounts as of specified day. 
   * @return asOfDayNetMrr
   */
  @javax.annotation.Nullable
  public BigDecimal getAsOfDayNetMrr() {
    return asOfDayNetMrr;
  }

  public void setAsOfDayNetMrr(BigDecimal asOfDayNetMrr) {
    this.asOfDayNetMrr = asOfDayNetMrr;
  }


  public SubscriptionRatePlan ratePlanCharges(List ratePlanCharges) {
    this.ratePlanCharges = ratePlanCharges;
    return this;
  }

  public SubscriptionRatePlan addRatePlanChargesItem(GetSubscriptionRatePlanChargesWithAllSegments ratePlanChargesItem) {
    if (this.ratePlanCharges == null) {
      this.ratePlanCharges = new ArrayList<>();
    }
    this.ratePlanCharges.add(ratePlanChargesItem);
    return this;
  }

  /**
   * Container for one or more charges.
   * @return ratePlanCharges
   */
  @javax.annotation.Nullable
  public List getRatePlanCharges() {
    return ratePlanCharges;
  }

  public void setRatePlanCharges(List ratePlanCharges) {
    this.ratePlanCharges = ratePlanCharges;
  }

  /**
   * 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 SubscriptionRatePlan instance itself
   */
  public SubscriptionRatePlan 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;
    }
    SubscriptionRatePlan subscriptionRatePlan = (SubscriptionRatePlan) o;
    return Objects.equals(this.id, subscriptionRatePlan.id) &&
        Objects.equals(this.subscriptionRatePlanNumber, subscriptionRatePlan.subscriptionRatePlanNumber) &&
        Objects.equals(this.isFromExternalCatalog, subscriptionRatePlan.isFromExternalCatalog) &&
        Objects.equals(this.lastChangeType, subscriptionRatePlan.lastChangeType) &&
        Objects.equals(this.productId, subscriptionRatePlan.productId) &&
        Objects.equals(this.productName, subscriptionRatePlan.productName) &&
        Objects.equals(this.productSku, subscriptionRatePlan.productSku) &&
        Objects.equals(this.productRatePlanId, subscriptionRatePlan.productRatePlanId) &&
        Objects.equals(this.productRatePlanNumber, subscriptionRatePlan.productRatePlanNumber) &&
        Objects.equals(this.ratePlanName, subscriptionRatePlan.ratePlanName) &&
        Objects.equals(this.subscriptionProductFeatures, subscriptionRatePlan.subscriptionProductFeatures) &&
        Objects.equals(this.externallyManagedPlanId, subscriptionRatePlan.externallyManagedPlanId) &&
        Objects.equals(this.contractedMrr, subscriptionRatePlan.contractedMrr) &&
        Objects.equals(this.contractedNetMrr, subscriptionRatePlan.contractedNetMrr) &&
        Objects.equals(this.asOfDayGrossMrr, subscriptionRatePlan.asOfDayGrossMrr) &&
        Objects.equals(this.asOfDayNetMrr, subscriptionRatePlan.asOfDayNetMrr) &&
        Objects.equals(this.ratePlanCharges, subscriptionRatePlan.ratePlanCharges)&&
        Objects.equals(this.additionalProperties, subscriptionRatePlan.additionalProperties);
  }

  @Override
  public int hashCode() {
    return Objects.hash(id, subscriptionRatePlanNumber, isFromExternalCatalog, lastChangeType, productId, productName, productSku, productRatePlanId, productRatePlanNumber, ratePlanName, subscriptionProductFeatures, externallyManagedPlanId, contractedMrr, contractedNetMrr, asOfDayGrossMrr, asOfDayNetMrr, ratePlanCharges, additionalProperties);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class SubscriptionRatePlan {\n");
    sb.append("    id: ").append(toIndentedString(id)).append("\n");
    sb.append("    subscriptionRatePlanNumber: ").append(toIndentedString(subscriptionRatePlanNumber)).append("\n");
    sb.append("    isFromExternalCatalog: ").append(toIndentedString(isFromExternalCatalog)).append("\n");
    sb.append("    lastChangeType: ").append(toIndentedString(lastChangeType)).append("\n");
    sb.append("    productId: ").append(toIndentedString(productId)).append("\n");
    sb.append("    productName: ").append(toIndentedString(productName)).append("\n");
    sb.append("    productSku: ").append(toIndentedString(productSku)).append("\n");
    sb.append("    productRatePlanId: ").append(toIndentedString(productRatePlanId)).append("\n");
    sb.append("    productRatePlanNumber: ").append(toIndentedString(productRatePlanNumber)).append("\n");
    sb.append("    ratePlanName: ").append(toIndentedString(ratePlanName)).append("\n");
    sb.append("    subscriptionProductFeatures: ").append(toIndentedString(subscriptionProductFeatures)).append("\n");
    sb.append("    externallyManagedPlanId: ").append(toIndentedString(externallyManagedPlanId)).append("\n");
    sb.append("    contractedMrr: ").append(toIndentedString(contractedMrr)).append("\n");
    sb.append("    contractedNetMrr: ").append(toIndentedString(contractedNetMrr)).append("\n");
    sb.append("    asOfDayGrossMrr: ").append(toIndentedString(asOfDayGrossMrr)).append("\n");
    sb.append("    asOfDayNetMrr: ").append(toIndentedString(asOfDayNetMrr)).append("\n");
    sb.append("    ratePlanCharges: ").append(toIndentedString(ratePlanCharges)).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("id");
    openapiFields.add("subscriptionRatePlanNumber");
    openapiFields.add("isFromExternalCatalog");
    openapiFields.add("lastChangeType");
    openapiFields.add("productId");
    openapiFields.add("productName");
    openapiFields.add("productSku");
    openapiFields.add("productRatePlanId");
    openapiFields.add("productRatePlanNumber");
    openapiFields.add("ratePlanName");
    openapiFields.add("subscriptionProductFeatures");
    openapiFields.add("externallyManagedPlanId");
    openapiFields.add("contractedMrr");
    openapiFields.add("contractedNetMrr");
    openapiFields.add("asOfDayGrossMrr");
    openapiFields.add("asOfDayNetMrr");
    openapiFields.add("ratePlanCharges");

    // a set of required properties/fields (JSON key names)
    openapiRequiredFields = new HashSet();
  }

  /**
   * 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 SubscriptionRatePlan
   */
  public static void validateJsonElement(JsonElement jsonElement) throws IOException {
      if (jsonElement == null) {
        if (!SubscriptionRatePlan.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null
          throw new IllegalArgumentException(String.format("The required field(s) %s in SubscriptionRatePlan is not found in the empty JSON string", SubscriptionRatePlan.openapiRequiredFields.toString()));
        }
      }
        JsonObject jsonObj = jsonElement.getAsJsonObject();
      if ((jsonObj.get("id") != null && !jsonObj.get("id").isJsonNull()) && !jsonObj.get("id").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `id` to be a primitive type in the JSON string but got `%s`", jsonObj.get("id").toString()));
      }
      if ((jsonObj.get("subscriptionRatePlanNumber") != null && !jsonObj.get("subscriptionRatePlanNumber").isJsonNull()) && !jsonObj.get("subscriptionRatePlanNumber").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `subscriptionRatePlanNumber` to be a primitive type in the JSON string but got `%s`", jsonObj.get("subscriptionRatePlanNumber").toString()));
      }
      if ((jsonObj.get("lastChangeType") != null && !jsonObj.get("lastChangeType").isJsonNull()) && !jsonObj.get("lastChangeType").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `lastChangeType` to be a primitive type in the JSON string but got `%s`", jsonObj.get("lastChangeType").toString()));
      }
      // validate the optional field `lastChangeType`
      if (jsonObj.get("lastChangeType") != null && !jsonObj.get("lastChangeType").isJsonNull()) {
        LastChangeTypeEnum.validateJsonElement(jsonObj.get("lastChangeType"));
      }
      if ((jsonObj.get("productId") != null && !jsonObj.get("productId").isJsonNull()) && !jsonObj.get("productId").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `productId` to be a primitive type in the JSON string but got `%s`", jsonObj.get("productId").toString()));
      }
      if ((jsonObj.get("productName") != null && !jsonObj.get("productName").isJsonNull()) && !jsonObj.get("productName").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `productName` to be a primitive type in the JSON string but got `%s`", jsonObj.get("productName").toString()));
      }
      if ((jsonObj.get("productSku") != null && !jsonObj.get("productSku").isJsonNull()) && !jsonObj.get("productSku").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `productSku` to be a primitive type in the JSON string but got `%s`", jsonObj.get("productSku").toString()));
      }
      if ((jsonObj.get("productRatePlanId") != null && !jsonObj.get("productRatePlanId").isJsonNull()) && !jsonObj.get("productRatePlanId").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `productRatePlanId` to be a primitive type in the JSON string but got `%s`", jsonObj.get("productRatePlanId").toString()));
      }
      if ((jsonObj.get("productRatePlanNumber") != null && !jsonObj.get("productRatePlanNumber").isJsonNull()) && !jsonObj.get("productRatePlanNumber").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `productRatePlanNumber` to be a primitive type in the JSON string but got `%s`", jsonObj.get("productRatePlanNumber").toString()));
      }
      if ((jsonObj.get("ratePlanName") != null && !jsonObj.get("ratePlanName").isJsonNull()) && !jsonObj.get("ratePlanName").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `ratePlanName` to be a primitive type in the JSON string but got `%s`", jsonObj.get("ratePlanName").toString()));
      }
      if (jsonObj.get("subscriptionProductFeatures") != null && !jsonObj.get("subscriptionProductFeatures").isJsonNull()) {
        JsonArray jsonArraysubscriptionProductFeatures = jsonObj.getAsJsonArray("subscriptionProductFeatures");
        if (jsonArraysubscriptionProductFeatures != null) {
          // ensure the json data is an array
          if (!jsonObj.get("subscriptionProductFeatures").isJsonArray()) {
            throw new IllegalArgumentException(String.format("Expected the field `subscriptionProductFeatures` to be an array in the JSON string but got `%s`", jsonObj.get("subscriptionProductFeatures").toString()));
          }

          // validate the optional field `subscriptionProductFeatures` (array)
          for (int i = 0; i < jsonArraysubscriptionProductFeatures.size(); i++) {
            SubscriptionProductFeature.validateJsonElement(jsonArraysubscriptionProductFeatures.get(i));
          };
        }
      }
      if ((jsonObj.get("externallyManagedPlanId") != null && !jsonObj.get("externallyManagedPlanId").isJsonNull()) && !jsonObj.get("externallyManagedPlanId").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `externallyManagedPlanId` to be a primitive type in the JSON string but got `%s`", jsonObj.get("externallyManagedPlanId").toString()));
      }
      if (jsonObj.get("ratePlanCharges") != null && !jsonObj.get("ratePlanCharges").isJsonNull()) {
        JsonArray jsonArrayratePlanCharges = jsonObj.getAsJsonArray("ratePlanCharges");
        if (jsonArrayratePlanCharges != null) {
          // ensure the json data is an array
          if (!jsonObj.get("ratePlanCharges").isJsonArray()) {
            throw new IllegalArgumentException(String.format("Expected the field `ratePlanCharges` to be an array in the JSON string but got `%s`", jsonObj.get("ratePlanCharges").toString()));
          }

          // validate the optional field `ratePlanCharges` (array)
          for (int i = 0; i < jsonArrayratePlanCharges.size(); i++) {
            GetSubscriptionRatePlanChargesWithAllSegments.validateJsonElement(jsonArrayratePlanCharges.get(i));
          };
        }
      }
  }

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

       return (TypeAdapter) new TypeAdapter() {
           @Override
           public void write(JsonWriter out, SubscriptionRatePlan 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 SubscriptionRatePlan read(JsonReader in) throws IOException {
             JsonElement jsonElement = elementAdapter.read(in);
             validateJsonElement(jsonElement);
             JsonObject jsonObj = jsonElement.getAsJsonObject();
             // store additional fields in the deserialized instance
             SubscriptionRatePlan 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 SubscriptionRatePlan given an JSON string
   *
   * @param jsonString JSON string
   * @return An instance of SubscriptionRatePlan
   * @throws IOException if the JSON string is invalid with respect to SubscriptionRatePlan
   */
  public static SubscriptionRatePlan fromJson(String jsonString) throws IOException {
    return JSON.getGson().fromJson(jsonString, SubscriptionRatePlan.class);
  }

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





© 2015 - 2025 Weber Informatics LLC | Privacy Policy