sdks/java/src/main/java/com/konfigthis/client/model/UniversalActivity.java
<filename>sdks/java/src/main/java/com/konfigthis/client/model/UniversalActivity.java/*
 * SnapTrade
 * Connect brokerage accounts to your app for live positions and trading
 *
 * The version of the OpenAPI document: 1.0.0
 * Contact: kenaa@example.com
 *
 * NOTE: This class is auto generated by Konfig (https://konfigthis.com).
 * Do not edit the class manually.
 */


package com.konfigthis.client.model;

import java.util.Objects;
import java.util.Arrays;
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.konfigthis.client.model.AccountSimple;
import com.konfigthis.client.model.Currency;
import com.konfigthis.client.model.OptionsSymbol;
import com.konfigthis.client.model.Symbol;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.IOException;
import org.openapitools.jackson.nullable.JsonNullable;

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 org.apache.commons.lang3.StringUtils;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import com.konfigthis.client.JSON;

/**
 * A transaction or activity from an institution
 */
@ApiModel(description = "A transaction or activity from an institution")
@javax.annotation.Generated(value = "Generated by https://konfigthis.com")
public class UniversalActivity {
  public static final String SERIALIZED_NAME_ID = "id";
  @SerializedName(SERIALIZED_NAME_ID)
  private String id;

  public static final String SERIALIZED_NAME_ACCOUNT = "account";
  @SerializedName(SERIALIZED_NAME_ACCOUNT)
  private AccountSimple account;

  public static final String SERIALIZED_NAME_AMOUNT = "amount";
  @SerializedName(SERIALIZED_NAME_AMOUNT)
  private Double amount;

  public static final String SERIALIZED_NAME_CURRENCY = "currency";
  @SerializedName(SERIALIZED_NAME_CURRENCY)
  private Currency currency;

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

  public static final String SERIALIZED_NAME_FEE = "fee";
  @SerializedName(SERIALIZED_NAME_FEE)
  private Double fee;

  public static final String SERIALIZED_NAME_INSTITUTION = "institution";
  @SerializedName(SERIALIZED_NAME_INSTITUTION)
  private String institution;

  public static final String SERIALIZED_NAME_OPTION_TYPE = "option_type";
  @SerializedName(SERIALIZED_NAME_OPTION_TYPE)
  private String optionType;

  public static final String SERIALIZED_NAME_PRICE = "price";
  @SerializedName(SERIALIZED_NAME_PRICE)
  private Double price;

  public static final String SERIALIZED_NAME_SETTLEMENT_DATE = "settlement_date";
  @SerializedName(SERIALIZED_NAME_SETTLEMENT_DATE)
  private String settlementDate;

  public static final String SERIALIZED_NAME_EXTERNAL_REFERENCE_ID = "external_reference_id";
  @SerializedName(SERIALIZED_NAME_EXTERNAL_REFERENCE_ID)
  private String externalReferenceId;

  public static final String SERIALIZED_NAME_SYMBOL = "symbol";
  @SerializedName(SERIALIZED_NAME_SYMBOL)
  private Symbol symbol;

  public static final String SERIALIZED_NAME_OPTION_SYMBOL = "option_symbol";
  @SerializedName(SERIALIZED_NAME_OPTION_SYMBOL)
  private OptionsSymbol optionSymbol;

  public static final String SERIALIZED_NAME_TRADE_DATE = "trade_date";
  @SerializedName(SERIALIZED_NAME_TRADE_DATE)
  private String tradeDate;

  public static final String SERIALIZED_NAME_TYPE = "type";
  @SerializedName(SERIALIZED_NAME_TYPE)
  private String type;

  public static final String SERIALIZED_NAME_UNITS = "units";
  @SerializedName(SERIALIZED_NAME_UNITS)
  private Double units;

  public UniversalActivity() {
  }

  public UniversalActivity id(String id) {

    
    
    
    
    this.id = id;
    return this;
  }

   /**
   * Get id
   * @return id
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(example = "2f7dc9b3-5c33-4668-3440-2b31e056ebe6", value = "")

  public String getId() {
    return id;
  }


  public void setId(String id) {

    
    
    
    this.id = id;
  }


  public UniversalActivity account(AccountSimple account) {

    
    
    
    
    this.account = account;
    return this;
  }

   /**
   * Get account
   * @return account
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(value = "")

  public AccountSimple getAccount() {
    return account;
  }


  public void setAccount(AccountSimple account) {

    
    
    
    this.account = account;
  }


  public UniversalActivity amount(Double amount) {

    
    
    
    
    this.amount = amount;
    return this;
  }

  public UniversalActivity amount(Integer amount) {

    
    
    
    
    this.amount = amount.doubleValue();
    return this;
  }

   /**
   * Get amount
   * @return amount
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(example = "263.82", value = "")

  public Double getAmount() {
    return amount;
  }


  public void setAmount(Double amount) {

    
    
    
    this.amount = amount;
  }


  public UniversalActivity currency(Currency currency) {

    
    
    
    
    this.currency = currency;
    return this;
  }

   /**
   * Get currency
   * @return currency
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(value = "")

  public Currency getCurrency() {
    return currency;
  }


  public void setCurrency(Currency currency) {

    
    
    
    this.currency = currency;
  }


  public UniversalActivity description(String description) {

    
    
    
    
    this.description = description;
    return this;
  }

   /**
   * Get description
   * @return description
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(example = "WALT DISNEY UNIT DIST ON 21 SHS REC 12/31/21 PAY 01/06/22", value = "")

  public String getDescription() {
    return description;
  }


  public void setDescription(String description) {

    
    
    
    this.description = description;
  }


  public UniversalActivity fee(Double fee) {

    
    
    
    
    this.fee = fee;
    return this;
  }

  public UniversalActivity fee(Integer fee) {

    
    
    
    
    this.fee = fee.doubleValue();
    return this;
  }

   /**
   * Get fee
   * @return fee
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(example = "0", value = "")

  public Double getFee() {
    return fee;
  }


  public void setFee(Double fee) {

    
    
    
    this.fee = fee;
  }


  public UniversalActivity institution(String institution) {

    
    
    
    
    this.institution = institution;
    return this;
  }

   /**
   * Get institution
   * @return institution
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(example = "Passiv Investr", value = "")

  public String getInstitution() {
    return institution;
  }


  public void setInstitution(String institution) {

    
    
    
    this.institution = institution;
  }


  public UniversalActivity optionType(String optionType) {

    
    
    
    
    this.optionType = optionType;
    return this;
  }

   /**
   * If an option transaction, then it&#39;s type (BUY_TO_OPEN, SELL_TO_CLOSE, etc), otherwise empty string
   * @return optionType
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(example = "BUY_TO_OPEN", value = "If an option transaction, then it's type (BUY_TO_OPEN, SELL_TO_CLOSE, etc), otherwise empty string")

  public String getOptionType() {
    return optionType;
  }


  public void setOptionType(String optionType) {

    
    
    
    this.optionType = optionType;
  }


  public UniversalActivity price(Double price) {

    
    
    
    
    this.price = price;
    return this;
  }

  public UniversalActivity price(Integer price) {

    
    
    
    
    this.price = price.doubleValue();
    return this;
  }

   /**
   * Get price
   * @return price
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(example = "0.4", value = "")

  public Double getPrice() {
    return price;
  }


  public void setPrice(Double price) {

    
    
    
    this.price = price;
  }


  public UniversalActivity settlementDate(String settlementDate) {

    
    
    
    
    this.settlementDate = settlementDate;
    return this;
  }

   /**
   * Get settlementDate
   * @return settlementDate
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(example = "2022-01-06T05:00:00.000Z", value = "")

  public String getSettlementDate() {
    return settlementDate;
  }


  public void setSettlementDate(String settlementDate) {

    
    
    
    this.settlementDate = settlementDate;
  }


  public UniversalActivity externalReferenceId(String externalReferenceId) {

    
    
    
    
    this.externalReferenceId = externalReferenceId;
    return this;
  }

   /**
   * Reference ID from brokerage used to identify related transactions. For example if an order comprises of several transactions (buy, fee, fx), they can be grouped if they share the same external_reference_id
   * @return externalReferenceId
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(example = "2f7dc9b3-5c33-4668-3440-2b31e056ebe6", value = "Reference ID from brokerage used to identify related transactions. For example if an order comprises of several transactions (buy, fee, fx), they can be grouped if they share the same external_reference_id")

  public String getExternalReferenceId() {
    return externalReferenceId;
  }


  public void setExternalReferenceId(String externalReferenceId) {

    
    
    
    this.externalReferenceId = externalReferenceId;
  }


  public UniversalActivity symbol(Symbol symbol) {

    
    
    
    
    this.symbol = symbol;
    return this;
  }

   /**
   * Get symbol
   * @return symbol
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(value = "")

  public Symbol getSymbol() {
    return symbol;
  }


  public void setSymbol(Symbol symbol) {

    
    
    
    this.symbol = symbol;
  }


  public UniversalActivity optionSymbol(OptionsSymbol optionSymbol) {

    
    
    
    
    this.optionSymbol = optionSymbol;
    return this;
  }

   /**
   * Get optionSymbol
   * @return optionSymbol
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(value = "")

  public OptionsSymbol getOptionSymbol() {
    return optionSymbol;
  }


  public void setOptionSymbol(OptionsSymbol optionSymbol) {

    
    
    
    this.optionSymbol = optionSymbol;
  }


  public UniversalActivity tradeDate(String tradeDate) {

    
    
    
    
    this.tradeDate = tradeDate;
    return this;
  }

   /**
   * Get tradeDate
   * @return tradeDate
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(example = "2022-01-06T05:00:00.000Z", value = "")

  public String getTradeDate() {
    return tradeDate;
  }


  public void setTradeDate(String tradeDate) {

    
    
    
    this.tradeDate = tradeDate;
  }


  public UniversalActivity type(String type) {

    
    
    
    
    this.type = type;
    return this;
  }

   /**
   * Potential values include - DIVIDEND - BUY - SELL - CONTRIBUTION - WITHDRAWAL - EXTERNAL_ASSET_TRANSFER_IN - EXTERNAL_ASSET_TRANSFER_OUT - INTERNAL_CASH_TRANSFER_IN - INTERNAL_CASH_TRANSFER_OUT - INTERNAL_ASSET_TRANSFER_IN - INTERNAL_ASSET_TRANSFER_OUT - INTEREST - REBATE - GOV_GRANT - TAX - FEE - REI - FXT
   * @return type
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(value = "Potential values include - DIVIDEND - BUY - SELL - CONTRIBUTION - WITHDRAWAL - EXTERNAL_ASSET_TRANSFER_IN - EXTERNAL_ASSET_TRANSFER_OUT - INTERNAL_CASH_TRANSFER_IN - INTERNAL_CASH_TRANSFER_OUT - INTERNAL_ASSET_TRANSFER_IN - INTERNAL_ASSET_TRANSFER_OUT - INTEREST - REBATE - GOV_GRANT - TAX - FEE - REI - FXT")

  public String getType() {
    return type;
  }


  public void setType(String type) {

    
    
    
    this.type = type;
  }


  public UniversalActivity units(Double units) {

    
    
    
    
    this.units = units;
    return this;
  }

  public UniversalActivity units(Integer units) {

    
    
    
    
    this.units = units.doubleValue();
    return this;
  }

   /**
   * Usually but not necessarily an integer
   * @return units
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(example = "5", value = "Usually but not necessarily an integer")

  public Double getUnits() {
    return units;
  }


  public void setUnits(Double units) {

    
    
    
    this.units = units;
  }

  /**
   * 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<String, Object> 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 UniversalActivity instance itself
   */
  public UniversalActivity putAdditionalProperty(String key, Object value) {
    if (this.additionalProperties == null) {
        this.additionalProperties = new HashMap<String, Object>();
    }
    this.additionalProperties.put(key, value);
    return this;
  }

  /**
   * Return the additional (undeclared) property.
   *
   * @return a map of objects
   */
  public Map<String, Object> 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;
    }
    UniversalActivity universalActivity = (UniversalActivity) o;
    return Objects.equals(this.id, universalActivity.id) &&
        Objects.equals(this.account, universalActivity.account) &&
        Objects.equals(this.amount, universalActivity.amount) &&
        Objects.equals(this.currency, universalActivity.currency) &&
        Objects.equals(this.description, universalActivity.description) &&
        Objects.equals(this.fee, universalActivity.fee) &&
        Objects.equals(this.institution, universalActivity.institution) &&
        Objects.equals(this.optionType, universalActivity.optionType) &&
        Objects.equals(this.price, universalActivity.price) &&
        Objects.equals(this.settlementDate, universalActivity.settlementDate) &&
        Objects.equals(this.externalReferenceId, universalActivity.externalReferenceId) &&
        Objects.equals(this.symbol, universalActivity.symbol) &&
        Objects.equals(this.optionSymbol, universalActivity.optionSymbol) &&
        Objects.equals(this.tradeDate, universalActivity.tradeDate) &&
        Objects.equals(this.type, universalActivity.type) &&
        Objects.equals(this.units, universalActivity.units)&&
        Objects.equals(this.additionalProperties, universalActivity.additionalProperties);
  }

  private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
    return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && Objects.deepEquals(a.get(), b.get()));
  }

  @Override
  public int hashCode() {
    return Objects.hash(id, account, amount, currency, description, fee, institution, optionType, price, settlementDate, externalReferenceId, symbol, optionSymbol, tradeDate, type, units, additionalProperties);
  }

  private static <T> int hashCodeNullable(JsonNullable<T> a) {
    if (a == null) {
      return 1;
    }
    return a.isPresent() ? Arrays.deepHashCode(new Object[]{a.get()}) : 31;
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class UniversalActivity {\n");
    sb.append("    id: ").append(toIndentedString(id)).append("\n");
    sb.append("    account: ").append(toIndentedString(account)).append("\n");
    sb.append("    amount: ").append(toIndentedString(amount)).append("\n");
    sb.append("    currency: ").append(toIndentedString(currency)).append("\n");
    sb.append("    description: ").append(toIndentedString(description)).append("\n");
    sb.append("    fee: ").append(toIndentedString(fee)).append("\n");
    sb.append("    institution: ").append(toIndentedString(institution)).append("\n");
    sb.append("    optionType: ").append(toIndentedString(optionType)).append("\n");
    sb.append("    price: ").append(toIndentedString(price)).append("\n");
    sb.append("    settlementDate: ").append(toIndentedString(settlementDate)).append("\n");
    sb.append("    externalReferenceId: ").append(toIndentedString(externalReferenceId)).append("\n");
    sb.append("    symbol: ").append(toIndentedString(symbol)).append("\n");
    sb.append("    optionSymbol: ").append(toIndentedString(optionSymbol)).append("\n");
    sb.append("    tradeDate: ").append(toIndentedString(tradeDate)).append("\n");
    sb.append("    type: ").append(toIndentedString(type)).append("\n");
    sb.append("    units: ").append(toIndentedString(units)).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<String> openapiFields;
  public static HashSet<String> openapiRequiredFields;

  static {
    // a set of all properties/fields (JSON key names)
    openapiFields = new HashSet<String>();
    openapiFields.add("id");
    openapiFields.add("account");
    openapiFields.add("amount");
    openapiFields.add("currency");
    openapiFields.add("description");
    openapiFields.add("fee");
    openapiFields.add("institution");
    openapiFields.add("option_type");
    openapiFields.add("price");
    openapiFields.add("settlement_date");
    openapiFields.add("external_reference_id");
    openapiFields.add("symbol");
    openapiFields.add("option_symbol");
    openapiFields.add("trade_date");
    openapiFields.add("type");
    openapiFields.add("units");

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

 /**
  * Validates the JSON Object and throws an exception if issues found
  *
  * @param jsonObj JSON Object
  * @throws IOException if the JSON Object is invalid with respect to UniversalActivity
  */
  public static void validateJsonObject(JsonObject jsonObj) throws IOException {
      if (jsonObj == null) {
        if (!UniversalActivity.openapiRequiredFields.isEmpty()) { // has required fields but JSON object is null
          throw new IllegalArgumentException(String.format("The required field(s) %s in UniversalActivity is not found in the empty JSON string", UniversalActivity.openapiRequiredFields.toString()));
        }
      }
      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("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("institution") != null && !jsonObj.get("institution").isJsonNull()) && !jsonObj.get("institution").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `institution` to be a primitive type in the JSON string but got `%s`", jsonObj.get("institution").toString()));
      }
      if ((jsonObj.get("option_type") != null && !jsonObj.get("option_type").isJsonNull()) && !jsonObj.get("option_type").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `option_type` to be a primitive type in the JSON string but got `%s`", jsonObj.get("option_type").toString()));
      }
      if ((jsonObj.get("settlement_date") != null && !jsonObj.get("settlement_date").isJsonNull()) && !jsonObj.get("settlement_date").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `settlement_date` to be a primitive type in the JSON string but got `%s`", jsonObj.get("settlement_date").toString()));
      }
      if (!jsonObj.get("external_reference_id").isJsonNull() && (jsonObj.get("external_reference_id") != null && !jsonObj.get("external_reference_id").isJsonNull()) && !jsonObj.get("external_reference_id").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `external_reference_id` to be a primitive type in the JSON string but got `%s`", jsonObj.get("external_reference_id").toString()));
      }
      if (!jsonObj.get("trade_date").isJsonNull() && (jsonObj.get("trade_date") != null && !jsonObj.get("trade_date").isJsonNull()) && !jsonObj.get("trade_date").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `trade_date` to be a primitive type in the JSON string but got `%s`", jsonObj.get("trade_date").toString()));
      }
      if ((jsonObj.get("type") != null && !jsonObj.get("type").isJsonNull()) && !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()));
      }
  }

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

       return (TypeAdapter<T>) new TypeAdapter<UniversalActivity>() {
           @Override
           public void write(JsonWriter out, UniversalActivity value) throws IOException {
             JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
             obj.remove("additionalProperties");
             // serialize additonal properties
             if (value.getAdditionalProperties() != null) {
               for (Map.Entry<String, Object> 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 {
                   obj.add(entry.getKey(), gson.toJsonTree(entry.getValue()).getAsJsonObject());
                 }
               }
             }
             elementAdapter.write(out, obj);
           }

           @Override
           public UniversalActivity read(JsonReader in) throws IOException {
             JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
             validateJsonObject(jsonObj);
             // store additional fields in the deserialized instance
             UniversalActivity instance = thisAdapter.fromJsonTree(jsonObj);
             for (Map.Entry<String, JsonElement> 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 UniversalActivity given an JSON string
  *
  * @param jsonString JSON string
  * @return An instance of UniversalActivity
  * @throws IOException if the JSON string is invalid with respect to UniversalActivity
  */
  public static UniversalActivity fromJson(String jsonString) throws IOException {
    return JSON.getGson().fromJson(jsonString, UniversalActivity.class);
  }

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

