com.zuora.model.CreateOrderAction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zuora-sdk-java Show documentation
Show all versions of zuora-sdk-java Show documentation
The SDK of JAVA language for Zuora pricing system
/*
* 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.CreateOrderAddProduct;
import com.zuora.model.CreateOrderChangePlan;
import com.zuora.model.CreateOrderCreateSubscription;
import com.zuora.model.CreateOrderResume;
import com.zuora.model.CreateOrderSuspend;
import com.zuora.model.CreateOrderTermsAndConditions;
import com.zuora.model.CreateOrderUpdateProduct;
import com.zuora.model.OrderActionCancelSubscription;
import com.zuora.model.OrderActionOwnerTransfer;
import com.zuora.model.OrderActionRemoveProduct;
import com.zuora.model.OrderActionRenewSubscription;
import com.zuora.model.OrderActionType;
import com.zuora.model.TriggerDate;
import java.io.IOException;
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;
/**
* CreateOrderAction
*/
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.6.0")
public class CreateOrderAction {
public static final String SERIALIZED_NAME_CREATE_SUBSCRIPTION = "createSubscription";
@SerializedName(SERIALIZED_NAME_CREATE_SUBSCRIPTION)
private CreateOrderCreateSubscription createSubscription;
public static final String SERIALIZED_NAME_ADD_PRODUCT = "addProduct";
@SerializedName(SERIALIZED_NAME_ADD_PRODUCT)
private CreateOrderAddProduct addProduct;
public static final String SERIALIZED_NAME_UPDATE_PRODUCT = "updateProduct";
@SerializedName(SERIALIZED_NAME_UPDATE_PRODUCT)
private CreateOrderUpdateProduct updateProduct;
public static final String SERIALIZED_NAME_CHANGE_PLAN = "changePlan";
@SerializedName(SERIALIZED_NAME_CHANGE_PLAN)
private CreateOrderChangePlan changePlan;
public static final String SERIALIZED_NAME_OWNER_TRANSFER = "ownerTransfer";
@SerializedName(SERIALIZED_NAME_OWNER_TRANSFER)
private OrderActionOwnerTransfer ownerTransfer;
public static final String SERIALIZED_NAME_REMOVE_PRODUCT = "removeProduct";
@SerializedName(SERIALIZED_NAME_REMOVE_PRODUCT)
private OrderActionRemoveProduct removeProduct;
public static final String SERIALIZED_NAME_RENEW_SUBSCRIPTION = "renewSubscription";
@SerializedName(SERIALIZED_NAME_RENEW_SUBSCRIPTION)
private OrderActionRenewSubscription renewSubscription;
public static final String SERIALIZED_NAME_CANCEL_SUBSCRIPTION = "cancelSubscription";
@SerializedName(SERIALIZED_NAME_CANCEL_SUBSCRIPTION)
private OrderActionCancelSubscription cancelSubscription;
public static final String SERIALIZED_NAME_RESUME = "resume";
@SerializedName(SERIALIZED_NAME_RESUME)
private CreateOrderResume resume;
public static final String SERIALIZED_NAME_SUSPEND = "suspend";
@SerializedName(SERIALIZED_NAME_SUSPEND)
private CreateOrderSuspend suspend;
public static final String SERIALIZED_NAME_TERMS_AND_CONDITIONS = "termsAndConditions";
@SerializedName(SERIALIZED_NAME_TERMS_AND_CONDITIONS)
private CreateOrderTermsAndConditions termsAndConditions;
public static final String SERIALIZED_NAME_CHANGE_REASON = "changeReason";
@SerializedName(SERIALIZED_NAME_CHANGE_REASON)
private String changeReason;
public static final String SERIALIZED_NAME_TRIGGER_DATES = "triggerDates";
@SerializedName(SERIALIZED_NAME_TRIGGER_DATES)
private List triggerDates;
public static final String SERIALIZED_NAME_TYPE = "type";
@SerializedName(SERIALIZED_NAME_TYPE)
private OrderActionType type;
public static final String SERIALIZED_NAME_CUSTOM_FIELDS = "customFields";
@SerializedName(SERIALIZED_NAME_CUSTOM_FIELDS)
private Map customFields;
public CreateOrderAction() {
}
public CreateOrderAction createSubscription(CreateOrderCreateSubscription createSubscription) {
this.createSubscription = createSubscription;
return this;
}
/**
* Get createSubscription
* @return createSubscription
*/
@javax.annotation.Nullable
public CreateOrderCreateSubscription getCreateSubscription() {
return createSubscription;
}
public void setCreateSubscription(CreateOrderCreateSubscription createSubscription) {
this.createSubscription = createSubscription;
}
public CreateOrderAction addProduct(CreateOrderAddProduct addProduct) {
this.addProduct = addProduct;
return this;
}
/**
* Get addProduct
* @return addProduct
*/
@javax.annotation.Nullable
public CreateOrderAddProduct getAddProduct() {
return addProduct;
}
public void setAddProduct(CreateOrderAddProduct addProduct) {
this.addProduct = addProduct;
}
public CreateOrderAction updateProduct(CreateOrderUpdateProduct updateProduct) {
this.updateProduct = updateProduct;
return this;
}
/**
* Get updateProduct
* @return updateProduct
*/
@javax.annotation.Nullable
public CreateOrderUpdateProduct getUpdateProduct() {
return updateProduct;
}
public void setUpdateProduct(CreateOrderUpdateProduct updateProduct) {
this.updateProduct = updateProduct;
}
public CreateOrderAction changePlan(CreateOrderChangePlan changePlan) {
this.changePlan = changePlan;
return this;
}
/**
* Get changePlan
* @return changePlan
*/
@javax.annotation.Nullable
public CreateOrderChangePlan getChangePlan() {
return changePlan;
}
public void setChangePlan(CreateOrderChangePlan changePlan) {
this.changePlan = changePlan;
}
public CreateOrderAction ownerTransfer(OrderActionOwnerTransfer ownerTransfer) {
this.ownerTransfer = ownerTransfer;
return this;
}
/**
* Get ownerTransfer
* @return ownerTransfer
*/
@javax.annotation.Nullable
public OrderActionOwnerTransfer getOwnerTransfer() {
return ownerTransfer;
}
public void setOwnerTransfer(OrderActionOwnerTransfer ownerTransfer) {
this.ownerTransfer = ownerTransfer;
}
public CreateOrderAction removeProduct(OrderActionRemoveProduct removeProduct) {
this.removeProduct = removeProduct;
return this;
}
/**
* Get removeProduct
* @return removeProduct
*/
@javax.annotation.Nullable
public OrderActionRemoveProduct getRemoveProduct() {
return removeProduct;
}
public void setRemoveProduct(OrderActionRemoveProduct removeProduct) {
this.removeProduct = removeProduct;
}
public CreateOrderAction renewSubscription(OrderActionRenewSubscription renewSubscription) {
this.renewSubscription = renewSubscription;
return this;
}
/**
* Get renewSubscription
* @return renewSubscription
*/
@javax.annotation.Nullable
public OrderActionRenewSubscription getRenewSubscription() {
return renewSubscription;
}
public void setRenewSubscription(OrderActionRenewSubscription renewSubscription) {
this.renewSubscription = renewSubscription;
}
public CreateOrderAction cancelSubscription(OrderActionCancelSubscription cancelSubscription) {
this.cancelSubscription = cancelSubscription;
return this;
}
/**
* Get cancelSubscription
* @return cancelSubscription
*/
@javax.annotation.Nullable
public OrderActionCancelSubscription getCancelSubscription() {
return cancelSubscription;
}
public void setCancelSubscription(OrderActionCancelSubscription cancelSubscription) {
this.cancelSubscription = cancelSubscription;
}
public CreateOrderAction resume(CreateOrderResume resume) {
this.resume = resume;
return this;
}
/**
* Get resume
* @return resume
*/
@javax.annotation.Nullable
public CreateOrderResume getResume() {
return resume;
}
public void setResume(CreateOrderResume resume) {
this.resume = resume;
}
public CreateOrderAction suspend(CreateOrderSuspend suspend) {
this.suspend = suspend;
return this;
}
/**
* Get suspend
* @return suspend
*/
@javax.annotation.Nullable
public CreateOrderSuspend getSuspend() {
return suspend;
}
public void setSuspend(CreateOrderSuspend suspend) {
this.suspend = suspend;
}
public CreateOrderAction termsAndConditions(CreateOrderTermsAndConditions termsAndConditions) {
this.termsAndConditions = termsAndConditions;
return this;
}
/**
* Get termsAndConditions
* @return termsAndConditions
*/
@javax.annotation.Nullable
public CreateOrderTermsAndConditions getTermsAndConditions() {
return termsAndConditions;
}
public void setTermsAndConditions(CreateOrderTermsAndConditions termsAndConditions) {
this.termsAndConditions = termsAndConditions;
}
public CreateOrderAction changeReason(String changeReason) {
this.changeReason = changeReason;
return this;
}
/**
* The change reason set for an order action when an order is created.
* @return changeReason
*/
@javax.annotation.Nullable
public String getChangeReason() {
return changeReason;
}
public void setChangeReason(String changeReason) {
this.changeReason = changeReason;
}
public CreateOrderAction triggerDates(List triggerDates) {
this.triggerDates = triggerDates;
return this;
}
public CreateOrderAction addTriggerDatesItem(TriggerDate triggerDatesItem) {
if (this.triggerDates == null) {
this.triggerDates = new ArrayList<>();
}
this.triggerDates.add(triggerDatesItem);
return this;
}
/**
* Container for the contract effective, service activation, and customer acceptance dates of the order action. If [Zuora is configured to require service activation](https://knowledgecenter.zuora.com/CB_Billing/Billing_Settings/Define_Default_Subscription_Settings#Require_Service_Activation_of_Orders.3F) and the `ServiceActivation` field is not set for a `CreateSubscription` order action, a `Pending` order and a `Pending Activation` subscription are created. If [Zuora is configured to require customer acceptance](https://knowledgecenter.zuora.com/CB_Billing/Billing_Settings/Define_Default_Subscription_Settings#Require_Customer_Acceptance_of_Orders.3F) and the `CustomerAcceptance` field is not set for a `CreateSubscription` order action, a `Pending` order and a `Pending Acceptance` subscription are created. At the same time, if the service activation date field is also required and not set, a `Pending` order and a `Pending Activation` subscription are created instead. If [Zuora is configured to require service activation](https://knowledgecenter.zuora.com/CB_Billing/Billing_Settings/Define_Default_Subscription_Settings#Require_Service_Activation_of_Orders.3F) and the `ServiceActivation` field is not set for either of the following order actions, a `Pending` order is created. The subscription status is not impacted. **Note:** This feature is in **Limited Availability**. If you want to have access to the feature, submit a request at [Zuora Global Support](http://support.zuora.com/). * AddProduct * UpdateProduct * RemoveProduct * RenewSubscription * TermsAndConditions If [Zuora is configured to require customer acceptance](https://knowledgecenter.zuora.com/CB_Billing/Billing_Settings/Define_Default_Subscription_Settings#Require_Customer_Acceptance_of_Orders.3F) and the `CustomerAcceptance` field is not set for either of the following order actions, a `Pending` order is created. The subscription status is not impacted. **Note:** This feature is in **Limited Availability**. If you want to have access to the feature, submit a request at [Zuora Global Support](http://support.zuora.com/). * AddProduct * UpdateProduct * RemoveProduct * RenewSubscription * TermsAndConditions
* @return triggerDates
*/
@javax.annotation.Nullable
public List getTriggerDates() {
return triggerDates;
}
public void setTriggerDates(List triggerDates) {
this.triggerDates = triggerDates;
}
public CreateOrderAction type(OrderActionType type) {
this.type = type;
return this;
}
/**
* Get type
* @return type
*/
@javax.annotation.Nonnull
public OrderActionType getType() {
return type;
}
public void setType(OrderActionType type) {
this.type = type;
}
public CreateOrderAction customFields(Map customFields) {
this.customFields = customFields;
return this;
}
public CreateOrderAction 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 an Order Action object.
* @return customFields
*/
@javax.annotation.Nullable
public Map getCustomFields() {
return customFields;
}
public void setCustomFields(Map customFields) {
this.customFields = customFields;
}
/**
* 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 CreateOrderAction instance itself
*/
public CreateOrderAction 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;
}
CreateOrderAction createOrderAction = (CreateOrderAction) o;
return Objects.equals(this.createSubscription, createOrderAction.createSubscription) &&
Objects.equals(this.addProduct, createOrderAction.addProduct) &&
Objects.equals(this.updateProduct, createOrderAction.updateProduct) &&
Objects.equals(this.changePlan, createOrderAction.changePlan) &&
Objects.equals(this.ownerTransfer, createOrderAction.ownerTransfer) &&
Objects.equals(this.removeProduct, createOrderAction.removeProduct) &&
Objects.equals(this.renewSubscription, createOrderAction.renewSubscription) &&
Objects.equals(this.cancelSubscription, createOrderAction.cancelSubscription) &&
Objects.equals(this.resume, createOrderAction.resume) &&
Objects.equals(this.suspend, createOrderAction.suspend) &&
Objects.equals(this.termsAndConditions, createOrderAction.termsAndConditions) &&
Objects.equals(this.changeReason, createOrderAction.changeReason) &&
Objects.equals(this.triggerDates, createOrderAction.triggerDates) &&
Objects.equals(this.type, createOrderAction.type) &&
Objects.equals(this.customFields, createOrderAction.customFields)&&
Objects.equals(this.additionalProperties, createOrderAction.additionalProperties);
}
@Override
public int hashCode() {
return Objects.hash(createSubscription, addProduct, updateProduct, changePlan, ownerTransfer, removeProduct, renewSubscription, cancelSubscription, resume, suspend, termsAndConditions, changeReason, triggerDates, type, customFields, additionalProperties);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class CreateOrderAction {\n");
sb.append(" createSubscription: ").append(toIndentedString(createSubscription)).append("\n");
sb.append(" addProduct: ").append(toIndentedString(addProduct)).append("\n");
sb.append(" updateProduct: ").append(toIndentedString(updateProduct)).append("\n");
sb.append(" changePlan: ").append(toIndentedString(changePlan)).append("\n");
sb.append(" ownerTransfer: ").append(toIndentedString(ownerTransfer)).append("\n");
sb.append(" removeProduct: ").append(toIndentedString(removeProduct)).append("\n");
sb.append(" renewSubscription: ").append(toIndentedString(renewSubscription)).append("\n");
sb.append(" cancelSubscription: ").append(toIndentedString(cancelSubscription)).append("\n");
sb.append(" resume: ").append(toIndentedString(resume)).append("\n");
sb.append(" suspend: ").append(toIndentedString(suspend)).append("\n");
sb.append(" termsAndConditions: ").append(toIndentedString(termsAndConditions)).append("\n");
sb.append(" changeReason: ").append(toIndentedString(changeReason)).append("\n");
sb.append(" triggerDates: ").append(toIndentedString(triggerDates)).append("\n");
sb.append(" type: ").append(toIndentedString(type)).append("\n");
sb.append(" customFields: ").append(toIndentedString(customFields)).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("createSubscription");
openapiFields.add("addProduct");
openapiFields.add("updateProduct");
openapiFields.add("changePlan");
openapiFields.add("ownerTransfer");
openapiFields.add("removeProduct");
openapiFields.add("renewSubscription");
openapiFields.add("cancelSubscription");
openapiFields.add("resume");
openapiFields.add("suspend");
openapiFields.add("termsAndConditions");
openapiFields.add("changeReason");
openapiFields.add("triggerDates");
openapiFields.add("type");
openapiFields.add("customFields");
// a set of required properties/fields (JSON key names)
openapiRequiredFields = new HashSet();
openapiRequiredFields.add("type");
}
/**
* 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 CreateOrderAction
*/
public static void validateJsonElement(JsonElement jsonElement) throws IOException {
if (jsonElement == null) {
if (!CreateOrderAction.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null
throw new IllegalArgumentException(String.format("The required field(s) %s in CreateOrderAction is not found in the empty JSON string", CreateOrderAction.openapiRequiredFields.toString()));
}
}
// check to make sure all required properties/fields are present in the JSON string
for (String requiredField : CreateOrderAction.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();
// validate the optional field `createSubscription`
if (jsonObj.get("createSubscription") != null && !jsonObj.get("createSubscription").isJsonNull()) {
CreateOrderCreateSubscription.validateJsonElement(jsonObj.get("createSubscription"));
}
// validate the optional field `addProduct`
if (jsonObj.get("addProduct") != null && !jsonObj.get("addProduct").isJsonNull()) {
CreateOrderAddProduct.validateJsonElement(jsonObj.get("addProduct"));
}
// validate the optional field `updateProduct`
if (jsonObj.get("updateProduct") != null && !jsonObj.get("updateProduct").isJsonNull()) {
CreateOrderUpdateProduct.validateJsonElement(jsonObj.get("updateProduct"));
}
// validate the optional field `changePlan`
if (jsonObj.get("changePlan") != null && !jsonObj.get("changePlan").isJsonNull()) {
CreateOrderChangePlan.validateJsonElement(jsonObj.get("changePlan"));
}
// validate the optional field `ownerTransfer`
if (jsonObj.get("ownerTransfer") != null && !jsonObj.get("ownerTransfer").isJsonNull()) {
OrderActionOwnerTransfer.validateJsonElement(jsonObj.get("ownerTransfer"));
}
// validate the optional field `removeProduct`
if (jsonObj.get("removeProduct") != null && !jsonObj.get("removeProduct").isJsonNull()) {
OrderActionRemoveProduct.validateJsonElement(jsonObj.get("removeProduct"));
}
// validate the optional field `renewSubscription`
if (jsonObj.get("renewSubscription") != null && !jsonObj.get("renewSubscription").isJsonNull()) {
OrderActionRenewSubscription.validateJsonElement(jsonObj.get("renewSubscription"));
}
// validate the optional field `cancelSubscription`
if (jsonObj.get("cancelSubscription") != null && !jsonObj.get("cancelSubscription").isJsonNull()) {
OrderActionCancelSubscription.validateJsonElement(jsonObj.get("cancelSubscription"));
}
// validate the optional field `resume`
if (jsonObj.get("resume") != null && !jsonObj.get("resume").isJsonNull()) {
CreateOrderResume.validateJsonElement(jsonObj.get("resume"));
}
// validate the optional field `suspend`
if (jsonObj.get("suspend") != null && !jsonObj.get("suspend").isJsonNull()) {
CreateOrderSuspend.validateJsonElement(jsonObj.get("suspend"));
}
// validate the optional field `termsAndConditions`
if (jsonObj.get("termsAndConditions") != null && !jsonObj.get("termsAndConditions").isJsonNull()) {
CreateOrderTermsAndConditions.validateJsonElement(jsonObj.get("termsAndConditions"));
}
if ((jsonObj.get("changeReason") != null && !jsonObj.get("changeReason").isJsonNull()) && !jsonObj.get("changeReason").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `changeReason` to be a primitive type in the JSON string but got `%s`", jsonObj.get("changeReason").toString()));
}
if (jsonObj.get("triggerDates") != null && !jsonObj.get("triggerDates").isJsonNull()) {
JsonArray jsonArraytriggerDates = jsonObj.getAsJsonArray("triggerDates");
if (jsonArraytriggerDates != null) {
// ensure the json data is an array
if (!jsonObj.get("triggerDates").isJsonArray()) {
throw new IllegalArgumentException(String.format("Expected the field `triggerDates` to be an array in the JSON string but got `%s`", jsonObj.get("triggerDates").toString()));
}
// validate the optional field `triggerDates` (array)
for (int i = 0; i < jsonArraytriggerDates.size(); i++) {
TriggerDate.validateJsonElement(jsonArraytriggerDates.get(i));
};
}
}
if (!jsonObj.get("type").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `type` to be a primitive type in the JSON string but got `%s`", jsonObj.get("type").toString()));
}
// validate the required field `type`
OrderActionType.validateJsonElement(jsonObj.get("type"));
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public TypeAdapter create(Gson gson, TypeToken type) {
if (!CreateOrderAction.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'CreateOrderAction' and its subtypes
}
final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(CreateOrderAction.class));
return (TypeAdapter) new TypeAdapter() {
@Override
public void write(JsonWriter out, CreateOrderAction 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 CreateOrderAction read(JsonReader in) throws IOException {
JsonElement jsonElement = elementAdapter.read(in);
validateJsonElement(jsonElement);
JsonObject jsonObj = jsonElement.getAsJsonObject();
// store additional fields in the deserialized instance
CreateOrderAction 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 CreateOrderAction given an JSON string
*
* @param jsonString JSON string
* @return An instance of CreateOrderAction
* @throws IOException if the JSON string is invalid with respect to CreateOrderAction
*/
public static CreateOrderAction fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, CreateOrderAction.class);
}
/**
* Convert an instance of CreateOrderAction to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy