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

com.zuora.model.Fulfillment 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.FulfillmentState;
import com.zuora.model.FulfillmentType;
import com.zuora.model.GetFulfillmentItem;
import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
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.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;

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

  public static final String SERIALIZED_NAME_CARRIER = "carrier";
  @SerializedName(SERIALIZED_NAME_CARRIER)
  private String carrier;

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

  public static final String SERIALIZED_NAME_DESCRIPTION = "description";
  @SerializedName(SERIALIZED_NAME_DESCRIPTION)
  private String description;

  public static final String SERIALIZED_NAME_EXCLUDE_ITEM_BILLING_FROM_REVENUE_ACCOUNTING = "excludeItemBillingFromRevenueAccounting";
  @SerializedName(SERIALIZED_NAME_EXCLUDE_ITEM_BILLING_FROM_REVENUE_ACCOUNTING)
  private Boolean excludeItemBillingFromRevenueAccounting;

  public static final String SERIALIZED_NAME_EXCLUDE_ITEM_BOOKING_FROM_REVENUE_ACCOUNTING = "excludeItemBookingFromRevenueAccounting";
  @SerializedName(SERIALIZED_NAME_EXCLUDE_ITEM_BOOKING_FROM_REVENUE_ACCOUNTING)
  private Boolean excludeItemBookingFromRevenueAccounting;

  public static final String SERIALIZED_NAME_EXTERNAL_ID = "externalId";
  @SerializedName(SERIALIZED_NAME_EXTERNAL_ID)
  private String externalId;

  public static final String SERIALIZED_NAME_FULFILLMENT_DATE = "fulfillmentDate";
  @SerializedName(SERIALIZED_NAME_FULFILLMENT_DATE)
  private LocalDate fulfillmentDate;

  public static final String SERIALIZED_NAME_FULFILLMENT_LOCATION = "fulfillmentLocation";
  @SerializedName(SERIALIZED_NAME_FULFILLMENT_LOCATION)
  private String fulfillmentLocation;

  public static final String SERIALIZED_NAME_FULFILLMENT_SYSTEM = "fulfillmentSystem";
  @SerializedName(SERIALIZED_NAME_FULFILLMENT_SYSTEM)
  private String fulfillmentSystem;

  public static final String SERIALIZED_NAME_FULFILLMENT_TYPE = "fulfillmentType";
  @SerializedName(SERIALIZED_NAME_FULFILLMENT_TYPE)
  private FulfillmentType fulfillmentType;

  public static final String SERIALIZED_NAME_ORDER_LINE_ITEM_ID = "orderLineItemId";
  @SerializedName(SERIALIZED_NAME_ORDER_LINE_ITEM_ID)
  private String orderLineItemId;

  public static final String SERIALIZED_NAME_QUANTITY = "quantity";
  @SerializedName(SERIALIZED_NAME_QUANTITY)
  private BigDecimal quantity;

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

  public static final String SERIALIZED_NAME_TRACKING_NUMBER = "trackingNumber";
  @SerializedName(SERIALIZED_NAME_TRACKING_NUMBER)
  private String trackingNumber;

  public static final String SERIALIZED_NAME_FULFILLMENT_ITEMS = "fulfillmentItems";
  @SerializedName(SERIALIZED_NAME_FULFILLMENT_ITEMS)
  private List fulfillmentItems;

  public Fulfillment() {
  }

  public Fulfillment billTargetDate(LocalDate billTargetDate) {
    this.billTargetDate = billTargetDate;
    return this;
  }

  /**
   * The target date for the Fulfillment to be picked up by bill run for billing. 
   * @return billTargetDate
   */
  @javax.annotation.Nullable
  public LocalDate getBillTargetDate() {
    return billTargetDate;
  }

  public void setBillTargetDate(LocalDate billTargetDate) {
    this.billTargetDate = billTargetDate;
  }


  public Fulfillment carrier(String carrier) {
    this.carrier = carrier;
    return this;
  }

  /**
   * The carrier of the Fulfillment. The available values can be configured in **Billing Settings** > **Fulfillment Settings** through Zuora UI. 
   * @return carrier
   */
  @javax.annotation.Nullable
  public String getCarrier() {
    return carrier;
  }

  public void setCarrier(String carrier) {
    this.carrier = carrier;
  }


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

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

  /**
   * Container for custom fields of a Fulfillment object. 
   * @return customFields
   */
  @javax.annotation.Nullable
  public Map getCustomFields() {
    return customFields;
  }

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


  public Fulfillment description(String description) {
    this.description = description;
    return this;
  }

  /**
   * The description of the Fulfillment. 
   * @return description
   */
  @javax.annotation.Nullable
  public String getDescription() {
    return description;
  }

  public void setDescription(String description) {
    this.description = description;
  }


  public Fulfillment excludeItemBillingFromRevenueAccounting(Boolean excludeItemBillingFromRevenueAccounting) {
    this.excludeItemBillingFromRevenueAccounting = excludeItemBillingFromRevenueAccounting;
    return this;
  }

  /**
   * The flag to exclude Fulfillment related invoice items, invoice item adjustments, credit memo items, and debit memo items from revenue accounting.   **Note**: This field is only available if you have the [Zuora Billing - Revenue Integration](https://knowledgecenter.zuora.com/Zuora_Revenue/Zuora_Billing_-_Revenue_Integration) feature enabled.  
   * @return excludeItemBillingFromRevenueAccounting
   */
  @javax.annotation.Nullable
  public Boolean getExcludeItemBillingFromRevenueAccounting() {
    return excludeItemBillingFromRevenueAccounting;
  }

  public void setExcludeItemBillingFromRevenueAccounting(Boolean excludeItemBillingFromRevenueAccounting) {
    this.excludeItemBillingFromRevenueAccounting = excludeItemBillingFromRevenueAccounting;
  }


  public Fulfillment excludeItemBookingFromRevenueAccounting(Boolean excludeItemBookingFromRevenueAccounting) {
    this.excludeItemBookingFromRevenueAccounting = excludeItemBookingFromRevenueAccounting;
    return this;
  }

  /**
   * The flag to exclude Fulfillment from revenue accounting.  **Note**: This field is only available if you have the [Zuora Billing - Revenue Integration](https://knowledgecenter.zuora.com/Zuora_Revenue/Zuora_Billing_-_Revenue_Integration) feature enabled.  
   * @return excludeItemBookingFromRevenueAccounting
   */
  @javax.annotation.Nullable
  public Boolean getExcludeItemBookingFromRevenueAccounting() {
    return excludeItemBookingFromRevenueAccounting;
  }

  public void setExcludeItemBookingFromRevenueAccounting(Boolean excludeItemBookingFromRevenueAccounting) {
    this.excludeItemBookingFromRevenueAccounting = excludeItemBookingFromRevenueAccounting;
  }


  public Fulfillment externalId(String externalId) {
    this.externalId = externalId;
    return this;
  }

  /**
   * The external id of the Fulfillment. 
   * @return externalId
   */
  @javax.annotation.Nullable
  public String getExternalId() {
    return externalId;
  }

  public void setExternalId(String externalId) {
    this.externalId = externalId;
  }


  public Fulfillment fulfillmentDate(LocalDate fulfillmentDate) {
    this.fulfillmentDate = fulfillmentDate;
    return this;
  }

  /**
   * The date of the Fulfillment. 
   * @return fulfillmentDate
   */
  @javax.annotation.Nullable
  public LocalDate getFulfillmentDate() {
    return fulfillmentDate;
  }

  public void setFulfillmentDate(LocalDate fulfillmentDate) {
    this.fulfillmentDate = fulfillmentDate;
  }


  public Fulfillment fulfillmentLocation(String fulfillmentLocation) {
    this.fulfillmentLocation = fulfillmentLocation;
    return this;
  }

  /**
   * The fulfillment location of the Fulfillment. The available values can be configured in **Billing Settings** > **Fulfillment Settings** through Zuora UI. 
   * @return fulfillmentLocation
   */
  @javax.annotation.Nullable
  public String getFulfillmentLocation() {
    return fulfillmentLocation;
  }

  public void setFulfillmentLocation(String fulfillmentLocation) {
    this.fulfillmentLocation = fulfillmentLocation;
  }


  public Fulfillment fulfillmentSystem(String fulfillmentSystem) {
    this.fulfillmentSystem = fulfillmentSystem;
    return this;
  }

  /**
   * The fulfillment system of the Fulfillment. The available values can be configured in **Billing Settings** > **Fulfillment Settings** through Zuora UI. 
   * @return fulfillmentSystem
   */
  @javax.annotation.Nullable
  public String getFulfillmentSystem() {
    return fulfillmentSystem;
  }

  public void setFulfillmentSystem(String fulfillmentSystem) {
    this.fulfillmentSystem = fulfillmentSystem;
  }


  public Fulfillment fulfillmentType(FulfillmentType fulfillmentType) {
    this.fulfillmentType = fulfillmentType;
    return this;
  }

  /**
   * Get fulfillmentType
   * @return fulfillmentType
   */
  @javax.annotation.Nullable
  public FulfillmentType getFulfillmentType() {
    return fulfillmentType;
  }

  public void setFulfillmentType(FulfillmentType fulfillmentType) {
    this.fulfillmentType = fulfillmentType;
  }


  public Fulfillment orderLineItemId(String orderLineItemId) {
    this.orderLineItemId = orderLineItemId;
    return this;
  }

  /**
   * The reference id of the related Order Line Item. 
   * @return orderLineItemId
   */
  @javax.annotation.Nullable
  public String getOrderLineItemId() {
    return orderLineItemId;
  }

  public void setOrderLineItemId(String orderLineItemId) {
    this.orderLineItemId = orderLineItemId;
  }


  public Fulfillment quantity(BigDecimal quantity) {
    this.quantity = quantity;
    return this;
  }

  /**
   * The quantity of the Fulfillment. 
   * @return quantity
   */
  @javax.annotation.Nullable
  public BigDecimal getQuantity() {
    return quantity;
  }

  public void setQuantity(BigDecimal quantity) {
    this.quantity = quantity;
  }


  public Fulfillment state(FulfillmentState state) {
    this.state = state;
    return this;
  }

  /**
   * Get state
   * @return state
   */
  @javax.annotation.Nullable
  public FulfillmentState getState() {
    return state;
  }

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


  public Fulfillment trackingNumber(String trackingNumber) {
    this.trackingNumber = trackingNumber;
    return this;
  }

  /**
   * The tracking number of the Fulfillment. 
   * @return trackingNumber
   */
  @javax.annotation.Nullable
  public String getTrackingNumber() {
    return trackingNumber;
  }

  public void setTrackingNumber(String trackingNumber) {
    this.trackingNumber = trackingNumber;
  }


  public Fulfillment fulfillmentItems(List fulfillmentItems) {
    this.fulfillmentItems = fulfillmentItems;
    return this;
  }

  public Fulfillment addFulfillmentItemsItem(GetFulfillmentItem fulfillmentItemsItem) {
    if (this.fulfillmentItems == null) {
      this.fulfillmentItems = new ArrayList<>();
    }
    this.fulfillmentItems.add(fulfillmentItemsItem);
    return this;
  }

  /**
   * The fulfillmentItems of the Fulfillment
   * @return fulfillmentItems
   */
  @javax.annotation.Nullable
  public List getFulfillmentItems() {
    return fulfillmentItems;
  }

  public void setFulfillmentItems(List fulfillmentItems) {
    this.fulfillmentItems = fulfillmentItems;
  }

  /**
   * 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 Fulfillment instance itself
   */
  public Fulfillment 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;
    }
    Fulfillment fulfillment = (Fulfillment) o;
    return Objects.equals(this.billTargetDate, fulfillment.billTargetDate) &&
        Objects.equals(this.carrier, fulfillment.carrier) &&
        Objects.equals(this.customFields, fulfillment.customFields) &&
        Objects.equals(this.description, fulfillment.description) &&
        Objects.equals(this.excludeItemBillingFromRevenueAccounting, fulfillment.excludeItemBillingFromRevenueAccounting) &&
        Objects.equals(this.excludeItemBookingFromRevenueAccounting, fulfillment.excludeItemBookingFromRevenueAccounting) &&
        Objects.equals(this.externalId, fulfillment.externalId) &&
        Objects.equals(this.fulfillmentDate, fulfillment.fulfillmentDate) &&
        Objects.equals(this.fulfillmentLocation, fulfillment.fulfillmentLocation) &&
        Objects.equals(this.fulfillmentSystem, fulfillment.fulfillmentSystem) &&
        Objects.equals(this.fulfillmentType, fulfillment.fulfillmentType) &&
        Objects.equals(this.orderLineItemId, fulfillment.orderLineItemId) &&
        Objects.equals(this.quantity, fulfillment.quantity) &&
        Objects.equals(this.state, fulfillment.state) &&
        Objects.equals(this.trackingNumber, fulfillment.trackingNumber) &&
        Objects.equals(this.fulfillmentItems, fulfillment.fulfillmentItems)&&
        Objects.equals(this.additionalProperties, fulfillment.additionalProperties);
  }

  @Override
  public int hashCode() {
    return Objects.hash(billTargetDate, carrier, customFields, description, excludeItemBillingFromRevenueAccounting, excludeItemBookingFromRevenueAccounting, externalId, fulfillmentDate, fulfillmentLocation, fulfillmentSystem, fulfillmentType, orderLineItemId, quantity, state, trackingNumber, fulfillmentItems, additionalProperties);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class Fulfillment {\n");
    sb.append("    billTargetDate: ").append(toIndentedString(billTargetDate)).append("\n");
    sb.append("    carrier: ").append(toIndentedString(carrier)).append("\n");
    sb.append("    customFields: ").append(toIndentedString(customFields)).append("\n");
    sb.append("    description: ").append(toIndentedString(description)).append("\n");
    sb.append("    excludeItemBillingFromRevenueAccounting: ").append(toIndentedString(excludeItemBillingFromRevenueAccounting)).append("\n");
    sb.append("    excludeItemBookingFromRevenueAccounting: ").append(toIndentedString(excludeItemBookingFromRevenueAccounting)).append("\n");
    sb.append("    externalId: ").append(toIndentedString(externalId)).append("\n");
    sb.append("    fulfillmentDate: ").append(toIndentedString(fulfillmentDate)).append("\n");
    sb.append("    fulfillmentLocation: ").append(toIndentedString(fulfillmentLocation)).append("\n");
    sb.append("    fulfillmentSystem: ").append(toIndentedString(fulfillmentSystem)).append("\n");
    sb.append("    fulfillmentType: ").append(toIndentedString(fulfillmentType)).append("\n");
    sb.append("    orderLineItemId: ").append(toIndentedString(orderLineItemId)).append("\n");
    sb.append("    quantity: ").append(toIndentedString(quantity)).append("\n");
    sb.append("    state: ").append(toIndentedString(state)).append("\n");
    sb.append("    trackingNumber: ").append(toIndentedString(trackingNumber)).append("\n");
    sb.append("    fulfillmentItems: ").append(toIndentedString(fulfillmentItems)).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("billTargetDate");
    openapiFields.add("carrier");
    openapiFields.add("customFields");
    openapiFields.add("description");
    openapiFields.add("excludeItemBillingFromRevenueAccounting");
    openapiFields.add("excludeItemBookingFromRevenueAccounting");
    openapiFields.add("externalId");
    openapiFields.add("fulfillmentDate");
    openapiFields.add("fulfillmentLocation");
    openapiFields.add("fulfillmentSystem");
    openapiFields.add("fulfillmentType");
    openapiFields.add("orderLineItemId");
    openapiFields.add("quantity");
    openapiFields.add("state");
    openapiFields.add("trackingNumber");
    openapiFields.add("fulfillmentItems");

    // 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 Fulfillment
   */
  public static void validateJsonElement(JsonElement jsonElement) throws IOException {
      if (jsonElement == null) {
        if (!Fulfillment.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null
          throw new IllegalArgumentException(String.format("The required field(s) %s in Fulfillment is not found in the empty JSON string", Fulfillment.openapiRequiredFields.toString()));
        }
      }
        JsonObject jsonObj = jsonElement.getAsJsonObject();
      if ((jsonObj.get("carrier") != null && !jsonObj.get("carrier").isJsonNull()) && !jsonObj.get("carrier").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `carrier` to be a primitive type in the JSON string but got `%s`", jsonObj.get("carrier").toString()));
      }
      if ((jsonObj.get("description") != null && !jsonObj.get("description").isJsonNull()) && !jsonObj.get("description").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `description` to be a primitive type in the JSON string but got `%s`", jsonObj.get("description").toString()));
      }
      if ((jsonObj.get("externalId") != null && !jsonObj.get("externalId").isJsonNull()) && !jsonObj.get("externalId").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `externalId` to be a primitive type in the JSON string but got `%s`", jsonObj.get("externalId").toString()));
      }
      if ((jsonObj.get("fulfillmentLocation") != null && !jsonObj.get("fulfillmentLocation").isJsonNull()) && !jsonObj.get("fulfillmentLocation").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `fulfillmentLocation` to be a primitive type in the JSON string but got `%s`", jsonObj.get("fulfillmentLocation").toString()));
      }
      if ((jsonObj.get("fulfillmentSystem") != null && !jsonObj.get("fulfillmentSystem").isJsonNull()) && !jsonObj.get("fulfillmentSystem").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `fulfillmentSystem` to be a primitive type in the JSON string but got `%s`", jsonObj.get("fulfillmentSystem").toString()));
      }
      if ((jsonObj.get("fulfillmentType") != null && !jsonObj.get("fulfillmentType").isJsonNull()) && !jsonObj.get("fulfillmentType").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `fulfillmentType` to be a primitive type in the JSON string but got `%s`", jsonObj.get("fulfillmentType").toString()));
      }
      // validate the optional field `fulfillmentType`
      if (jsonObj.get("fulfillmentType") != null && !jsonObj.get("fulfillmentType").isJsonNull()) {
        FulfillmentType.validateJsonElement(jsonObj.get("fulfillmentType"));
      }
      if ((jsonObj.get("orderLineItemId") != null && !jsonObj.get("orderLineItemId").isJsonNull()) && !jsonObj.get("orderLineItemId").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `orderLineItemId` to be a primitive type in the JSON string but got `%s`", jsonObj.get("orderLineItemId").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()));
      }
      // validate the optional field `state`
      if (jsonObj.get("state") != null && !jsonObj.get("state").isJsonNull()) {
        FulfillmentState.validateJsonElement(jsonObj.get("state"));
      }
      if ((jsonObj.get("trackingNumber") != null && !jsonObj.get("trackingNumber").isJsonNull()) && !jsonObj.get("trackingNumber").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `trackingNumber` to be a primitive type in the JSON string but got `%s`", jsonObj.get("trackingNumber").toString()));
      }
      if (jsonObj.get("fulfillmentItems") != null && !jsonObj.get("fulfillmentItems").isJsonNull()) {
        JsonArray jsonArrayfulfillmentItems = jsonObj.getAsJsonArray("fulfillmentItems");
        if (jsonArrayfulfillmentItems != null) {
          // ensure the json data is an array
          if (!jsonObj.get("fulfillmentItems").isJsonArray()) {
            throw new IllegalArgumentException(String.format("Expected the field `fulfillmentItems` to be an array in the JSON string but got `%s`", jsonObj.get("fulfillmentItems").toString()));
          }

          // validate the optional field `fulfillmentItems` (array)
          for (int i = 0; i < jsonArrayfulfillmentItems.size(); i++) {
            GetFulfillmentItem.validateJsonElement(jsonArrayfulfillmentItems.get(i));
          };
        }
      }
  }

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

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

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





© 2015 - 2025 Weber Informatics LLC | Privacy Policy