mirror of
https://github.com/Tribufu/TribufuJava
synced 2026-08-11 22:01:07 +00:00
716 lines
23 KiB
Java
716 lines
23 KiB
Java
/*
|
|
* Tribufu API
|
|
* REST API to access Tribufu services.
|
|
*
|
|
* The version of the OpenAPI document: 1.1.0
|
|
* Contact: contact@tribufu.com
|
|
*
|
|
* 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.tribufu.generated.models;
|
|
|
|
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 java.io.IOException;
|
|
import java.util.Arrays;
|
|
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 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.List;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
|
|
import com.tribufu.generated.JSON;
|
|
|
|
/**
|
|
* IpAddress
|
|
*/
|
|
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2025-05-26T22:04:46.763378600-03:00[America/Sao_Paulo]", comments = "Generator version: 7.12.0")
|
|
public class IpAddress {
|
|
public static final String SERIALIZED_NAME_ADDRESS = "address";
|
|
@SerializedName(SERIALIZED_NAME_ADDRESS)
|
|
@javax.annotation.Nullable
|
|
private String address;
|
|
|
|
public static final String SERIALIZED_NAME_VERSION = "version";
|
|
@SerializedName(SERIALIZED_NAME_VERSION)
|
|
@javax.annotation.Nullable
|
|
private Integer version;
|
|
|
|
public static final String SERIALIZED_NAME_NETWORK = "network";
|
|
@SerializedName(SERIALIZED_NAME_NETWORK)
|
|
@javax.annotation.Nullable
|
|
private String network;
|
|
|
|
public static final String SERIALIZED_NAME_RESERVED = "reserved";
|
|
@SerializedName(SERIALIZED_NAME_RESERVED)
|
|
@javax.annotation.Nullable
|
|
private Boolean reserved;
|
|
|
|
public static final String SERIALIZED_NAME_ASN = "asn";
|
|
@SerializedName(SERIALIZED_NAME_ASN)
|
|
@javax.annotation.Nullable
|
|
private String asn;
|
|
|
|
public static final String SERIALIZED_NAME_ISP = "isp";
|
|
@SerializedName(SERIALIZED_NAME_ISP)
|
|
@javax.annotation.Nullable
|
|
private String isp;
|
|
|
|
public static final String SERIALIZED_NAME_CONTINENT = "continent";
|
|
@SerializedName(SERIALIZED_NAME_CONTINENT)
|
|
@javax.annotation.Nullable
|
|
private String continent;
|
|
|
|
public static final String SERIALIZED_NAME_COUNTRY = "country";
|
|
@SerializedName(SERIALIZED_NAME_COUNTRY)
|
|
@javax.annotation.Nullable
|
|
private String country;
|
|
|
|
public static final String SERIALIZED_NAME_REGION = "region";
|
|
@SerializedName(SERIALIZED_NAME_REGION)
|
|
@javax.annotation.Nullable
|
|
private String region;
|
|
|
|
public static final String SERIALIZED_NAME_CITY = "city";
|
|
@SerializedName(SERIALIZED_NAME_CITY)
|
|
@javax.annotation.Nullable
|
|
private String city;
|
|
|
|
public static final String SERIALIZED_NAME_POSTAL_CODE = "postal_code";
|
|
@SerializedName(SERIALIZED_NAME_POSTAL_CODE)
|
|
@javax.annotation.Nullable
|
|
private String postalCode;
|
|
|
|
public static final String SERIALIZED_NAME_CALLING_CODE = "calling_code";
|
|
@SerializedName(SERIALIZED_NAME_CALLING_CODE)
|
|
@javax.annotation.Nullable
|
|
private String callingCode;
|
|
|
|
public static final String SERIALIZED_NAME_TLD = "tld";
|
|
@SerializedName(SERIALIZED_NAME_TLD)
|
|
@javax.annotation.Nullable
|
|
private String tld;
|
|
|
|
public static final String SERIALIZED_NAME_LANGUAGE = "language";
|
|
@SerializedName(SERIALIZED_NAME_LANGUAGE)
|
|
@javax.annotation.Nullable
|
|
private String language;
|
|
|
|
public static final String SERIALIZED_NAME_TIMEZONE = "timezone";
|
|
@SerializedName(SERIALIZED_NAME_TIMEZONE)
|
|
@javax.annotation.Nullable
|
|
private String timezone;
|
|
|
|
public static final String SERIALIZED_NAME_CURRENCY = "currency";
|
|
@SerializedName(SERIALIZED_NAME_CURRENCY)
|
|
@javax.annotation.Nullable
|
|
private String currency;
|
|
|
|
public static final String SERIALIZED_NAME_LATITUDE = "latitude";
|
|
@SerializedName(SERIALIZED_NAME_LATITUDE)
|
|
@javax.annotation.Nullable
|
|
private Float latitude;
|
|
|
|
public static final String SERIALIZED_NAME_LONGITUDE = "longitude";
|
|
@SerializedName(SERIALIZED_NAME_LONGITUDE)
|
|
@javax.annotation.Nullable
|
|
private Float longitude;
|
|
|
|
public IpAddress() {
|
|
}
|
|
|
|
public IpAddress address(@javax.annotation.Nullable String address) {
|
|
this.address = address;
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Get address
|
|
* @return address
|
|
*/
|
|
@javax.annotation.Nullable
|
|
public String getAddress() {
|
|
return address;
|
|
}
|
|
|
|
public void setAddress(@javax.annotation.Nullable String address) {
|
|
this.address = address;
|
|
}
|
|
|
|
|
|
public IpAddress version(@javax.annotation.Nullable Integer version) {
|
|
this.version = version;
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Get version
|
|
* @return version
|
|
*/
|
|
@javax.annotation.Nullable
|
|
public Integer getVersion() {
|
|
return version;
|
|
}
|
|
|
|
public void setVersion(@javax.annotation.Nullable Integer version) {
|
|
this.version = version;
|
|
}
|
|
|
|
|
|
public IpAddress network(@javax.annotation.Nullable String network) {
|
|
this.network = network;
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Get network
|
|
* @return network
|
|
*/
|
|
@javax.annotation.Nullable
|
|
public String getNetwork() {
|
|
return network;
|
|
}
|
|
|
|
public void setNetwork(@javax.annotation.Nullable String network) {
|
|
this.network = network;
|
|
}
|
|
|
|
|
|
public IpAddress reserved(@javax.annotation.Nullable Boolean reserved) {
|
|
this.reserved = reserved;
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Get reserved
|
|
* @return reserved
|
|
*/
|
|
@javax.annotation.Nullable
|
|
public Boolean getReserved() {
|
|
return reserved;
|
|
}
|
|
|
|
public void setReserved(@javax.annotation.Nullable Boolean reserved) {
|
|
this.reserved = reserved;
|
|
}
|
|
|
|
|
|
public IpAddress asn(@javax.annotation.Nullable String asn) {
|
|
this.asn = asn;
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Get asn
|
|
* @return asn
|
|
*/
|
|
@javax.annotation.Nullable
|
|
public String getAsn() {
|
|
return asn;
|
|
}
|
|
|
|
public void setAsn(@javax.annotation.Nullable String asn) {
|
|
this.asn = asn;
|
|
}
|
|
|
|
|
|
public IpAddress isp(@javax.annotation.Nullable String isp) {
|
|
this.isp = isp;
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Get isp
|
|
* @return isp
|
|
*/
|
|
@javax.annotation.Nullable
|
|
public String getIsp() {
|
|
return isp;
|
|
}
|
|
|
|
public void setIsp(@javax.annotation.Nullable String isp) {
|
|
this.isp = isp;
|
|
}
|
|
|
|
|
|
public IpAddress continent(@javax.annotation.Nullable String continent) {
|
|
this.continent = continent;
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Get continent
|
|
* @return continent
|
|
*/
|
|
@javax.annotation.Nullable
|
|
public String getContinent() {
|
|
return continent;
|
|
}
|
|
|
|
public void setContinent(@javax.annotation.Nullable String continent) {
|
|
this.continent = continent;
|
|
}
|
|
|
|
|
|
public IpAddress country(@javax.annotation.Nullable String country) {
|
|
this.country = country;
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Get country
|
|
* @return country
|
|
*/
|
|
@javax.annotation.Nullable
|
|
public String getCountry() {
|
|
return country;
|
|
}
|
|
|
|
public void setCountry(@javax.annotation.Nullable String country) {
|
|
this.country = country;
|
|
}
|
|
|
|
|
|
public IpAddress region(@javax.annotation.Nullable String region) {
|
|
this.region = region;
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Get region
|
|
* @return region
|
|
*/
|
|
@javax.annotation.Nullable
|
|
public String getRegion() {
|
|
return region;
|
|
}
|
|
|
|
public void setRegion(@javax.annotation.Nullable String region) {
|
|
this.region = region;
|
|
}
|
|
|
|
|
|
public IpAddress city(@javax.annotation.Nullable String city) {
|
|
this.city = city;
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Get city
|
|
* @return city
|
|
*/
|
|
@javax.annotation.Nullable
|
|
public String getCity() {
|
|
return city;
|
|
}
|
|
|
|
public void setCity(@javax.annotation.Nullable String city) {
|
|
this.city = city;
|
|
}
|
|
|
|
|
|
public IpAddress postalCode(@javax.annotation.Nullable String postalCode) {
|
|
this.postalCode = postalCode;
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Get postalCode
|
|
* @return postalCode
|
|
*/
|
|
@javax.annotation.Nullable
|
|
public String getPostalCode() {
|
|
return postalCode;
|
|
}
|
|
|
|
public void setPostalCode(@javax.annotation.Nullable String postalCode) {
|
|
this.postalCode = postalCode;
|
|
}
|
|
|
|
|
|
public IpAddress callingCode(@javax.annotation.Nullable String callingCode) {
|
|
this.callingCode = callingCode;
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Get callingCode
|
|
* @return callingCode
|
|
*/
|
|
@javax.annotation.Nullable
|
|
public String getCallingCode() {
|
|
return callingCode;
|
|
}
|
|
|
|
public void setCallingCode(@javax.annotation.Nullable String callingCode) {
|
|
this.callingCode = callingCode;
|
|
}
|
|
|
|
|
|
public IpAddress tld(@javax.annotation.Nullable String tld) {
|
|
this.tld = tld;
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Get tld
|
|
* @return tld
|
|
*/
|
|
@javax.annotation.Nullable
|
|
public String getTld() {
|
|
return tld;
|
|
}
|
|
|
|
public void setTld(@javax.annotation.Nullable String tld) {
|
|
this.tld = tld;
|
|
}
|
|
|
|
|
|
public IpAddress language(@javax.annotation.Nullable String language) {
|
|
this.language = language;
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Get language
|
|
* @return language
|
|
*/
|
|
@javax.annotation.Nullable
|
|
public String getLanguage() {
|
|
return language;
|
|
}
|
|
|
|
public void setLanguage(@javax.annotation.Nullable String language) {
|
|
this.language = language;
|
|
}
|
|
|
|
|
|
public IpAddress timezone(@javax.annotation.Nullable String timezone) {
|
|
this.timezone = timezone;
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Get timezone
|
|
* @return timezone
|
|
*/
|
|
@javax.annotation.Nullable
|
|
public String getTimezone() {
|
|
return timezone;
|
|
}
|
|
|
|
public void setTimezone(@javax.annotation.Nullable String timezone) {
|
|
this.timezone = timezone;
|
|
}
|
|
|
|
|
|
public IpAddress currency(@javax.annotation.Nullable String currency) {
|
|
this.currency = currency;
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Get currency
|
|
* @return currency
|
|
*/
|
|
@javax.annotation.Nullable
|
|
public String getCurrency() {
|
|
return currency;
|
|
}
|
|
|
|
public void setCurrency(@javax.annotation.Nullable String currency) {
|
|
this.currency = currency;
|
|
}
|
|
|
|
|
|
public IpAddress latitude(@javax.annotation.Nullable Float latitude) {
|
|
this.latitude = latitude;
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Get latitude
|
|
* @return latitude
|
|
*/
|
|
@javax.annotation.Nullable
|
|
public Float getLatitude() {
|
|
return latitude;
|
|
}
|
|
|
|
public void setLatitude(@javax.annotation.Nullable Float latitude) {
|
|
this.latitude = latitude;
|
|
}
|
|
|
|
|
|
public IpAddress longitude(@javax.annotation.Nullable Float longitude) {
|
|
this.longitude = longitude;
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Get longitude
|
|
* @return longitude
|
|
*/
|
|
@javax.annotation.Nullable
|
|
public Float getLongitude() {
|
|
return longitude;
|
|
}
|
|
|
|
public void setLongitude(@javax.annotation.Nullable Float longitude) {
|
|
this.longitude = longitude;
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
public boolean equals(Object o) {
|
|
if (this == o) {
|
|
return true;
|
|
}
|
|
if (o == null || getClass() != o.getClass()) {
|
|
return false;
|
|
}
|
|
IpAddress ipAddress = (IpAddress) o;
|
|
return Objects.equals(this.address, ipAddress.address) &&
|
|
Objects.equals(this.version, ipAddress.version) &&
|
|
Objects.equals(this.network, ipAddress.network) &&
|
|
Objects.equals(this.reserved, ipAddress.reserved) &&
|
|
Objects.equals(this.asn, ipAddress.asn) &&
|
|
Objects.equals(this.isp, ipAddress.isp) &&
|
|
Objects.equals(this.continent, ipAddress.continent) &&
|
|
Objects.equals(this.country, ipAddress.country) &&
|
|
Objects.equals(this.region, ipAddress.region) &&
|
|
Objects.equals(this.city, ipAddress.city) &&
|
|
Objects.equals(this.postalCode, ipAddress.postalCode) &&
|
|
Objects.equals(this.callingCode, ipAddress.callingCode) &&
|
|
Objects.equals(this.tld, ipAddress.tld) &&
|
|
Objects.equals(this.language, ipAddress.language) &&
|
|
Objects.equals(this.timezone, ipAddress.timezone) &&
|
|
Objects.equals(this.currency, ipAddress.currency) &&
|
|
Objects.equals(this.latitude, ipAddress.latitude) &&
|
|
Objects.equals(this.longitude, ipAddress.longitude);
|
|
}
|
|
|
|
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(address, version, network, reserved, asn, isp, continent, country, region, city, postalCode, callingCode, tld, language, timezone, currency, latitude, longitude);
|
|
}
|
|
|
|
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 IpAddress {\n");
|
|
sb.append(" address: ").append(toIndentedString(address)).append("\n");
|
|
sb.append(" version: ").append(toIndentedString(version)).append("\n");
|
|
sb.append(" network: ").append(toIndentedString(network)).append("\n");
|
|
sb.append(" reserved: ").append(toIndentedString(reserved)).append("\n");
|
|
sb.append(" asn: ").append(toIndentedString(asn)).append("\n");
|
|
sb.append(" isp: ").append(toIndentedString(isp)).append("\n");
|
|
sb.append(" continent: ").append(toIndentedString(continent)).append("\n");
|
|
sb.append(" country: ").append(toIndentedString(country)).append("\n");
|
|
sb.append(" region: ").append(toIndentedString(region)).append("\n");
|
|
sb.append(" city: ").append(toIndentedString(city)).append("\n");
|
|
sb.append(" postalCode: ").append(toIndentedString(postalCode)).append("\n");
|
|
sb.append(" callingCode: ").append(toIndentedString(callingCode)).append("\n");
|
|
sb.append(" tld: ").append(toIndentedString(tld)).append("\n");
|
|
sb.append(" language: ").append(toIndentedString(language)).append("\n");
|
|
sb.append(" timezone: ").append(toIndentedString(timezone)).append("\n");
|
|
sb.append(" currency: ").append(toIndentedString(currency)).append("\n");
|
|
sb.append(" latitude: ").append(toIndentedString(latitude)).append("\n");
|
|
sb.append(" longitude: ").append(toIndentedString(longitude)).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("address");
|
|
openapiFields.add("version");
|
|
openapiFields.add("network");
|
|
openapiFields.add("reserved");
|
|
openapiFields.add("asn");
|
|
openapiFields.add("isp");
|
|
openapiFields.add("continent");
|
|
openapiFields.add("country");
|
|
openapiFields.add("region");
|
|
openapiFields.add("city");
|
|
openapiFields.add("postal_code");
|
|
openapiFields.add("calling_code");
|
|
openapiFields.add("tld");
|
|
openapiFields.add("language");
|
|
openapiFields.add("timezone");
|
|
openapiFields.add("currency");
|
|
openapiFields.add("latitude");
|
|
openapiFields.add("longitude");
|
|
|
|
// a set of required properties/fields (JSON key names)
|
|
openapiRequiredFields = new HashSet<String>();
|
|
}
|
|
|
|
/**
|
|
* 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 IpAddress
|
|
*/
|
|
public static void validateJsonElement(JsonElement jsonElement) throws IOException {
|
|
if (jsonElement == null) {
|
|
if (!IpAddress.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null
|
|
throw new IllegalArgumentException(String.format("The required field(s) %s in IpAddress is not found in the empty JSON string", IpAddress.openapiRequiredFields.toString()));
|
|
}
|
|
}
|
|
|
|
Set<Map.Entry<String, JsonElement>> entries = jsonElement.getAsJsonObject().entrySet();
|
|
// check to see if the JSON string contains additional fields
|
|
for (Map.Entry<String, JsonElement> entry : entries) {
|
|
if (!IpAddress.openapiFields.contains(entry.getKey())) {
|
|
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `IpAddress` properties. JSON: %s", entry.getKey(), jsonElement.toString()));
|
|
}
|
|
}
|
|
JsonObject jsonObj = jsonElement.getAsJsonObject();
|
|
if ((jsonObj.get("address") != null && !jsonObj.get("address").isJsonNull()) && !jsonObj.get("address").isJsonPrimitive()) {
|
|
throw new IllegalArgumentException(String.format("Expected the field `address` to be a primitive type in the JSON string but got `%s`", jsonObj.get("address").toString()));
|
|
}
|
|
if ((jsonObj.get("network") != null && !jsonObj.get("network").isJsonNull()) && !jsonObj.get("network").isJsonPrimitive()) {
|
|
throw new IllegalArgumentException(String.format("Expected the field `network` to be a primitive type in the JSON string but got `%s`", jsonObj.get("network").toString()));
|
|
}
|
|
if ((jsonObj.get("asn") != null && !jsonObj.get("asn").isJsonNull()) && !jsonObj.get("asn").isJsonPrimitive()) {
|
|
throw new IllegalArgumentException(String.format("Expected the field `asn` to be a primitive type in the JSON string but got `%s`", jsonObj.get("asn").toString()));
|
|
}
|
|
if ((jsonObj.get("isp") != null && !jsonObj.get("isp").isJsonNull()) && !jsonObj.get("isp").isJsonPrimitive()) {
|
|
throw new IllegalArgumentException(String.format("Expected the field `isp` to be a primitive type in the JSON string but got `%s`", jsonObj.get("isp").toString()));
|
|
}
|
|
if ((jsonObj.get("continent") != null && !jsonObj.get("continent").isJsonNull()) && !jsonObj.get("continent").isJsonPrimitive()) {
|
|
throw new IllegalArgumentException(String.format("Expected the field `continent` to be a primitive type in the JSON string but got `%s`", jsonObj.get("continent").toString()));
|
|
}
|
|
if ((jsonObj.get("country") != null && !jsonObj.get("country").isJsonNull()) && !jsonObj.get("country").isJsonPrimitive()) {
|
|
throw new IllegalArgumentException(String.format("Expected the field `country` to be a primitive type in the JSON string but got `%s`", jsonObj.get("country").toString()));
|
|
}
|
|
if ((jsonObj.get("region") != null && !jsonObj.get("region").isJsonNull()) && !jsonObj.get("region").isJsonPrimitive()) {
|
|
throw new IllegalArgumentException(String.format("Expected the field `region` to be a primitive type in the JSON string but got `%s`", jsonObj.get("region").toString()));
|
|
}
|
|
if ((jsonObj.get("city") != null && !jsonObj.get("city").isJsonNull()) && !jsonObj.get("city").isJsonPrimitive()) {
|
|
throw new IllegalArgumentException(String.format("Expected the field `city` to be a primitive type in the JSON string but got `%s`", jsonObj.get("city").toString()));
|
|
}
|
|
if ((jsonObj.get("postal_code") != null && !jsonObj.get("postal_code").isJsonNull()) && !jsonObj.get("postal_code").isJsonPrimitive()) {
|
|
throw new IllegalArgumentException(String.format("Expected the field `postal_code` to be a primitive type in the JSON string but got `%s`", jsonObj.get("postal_code").toString()));
|
|
}
|
|
if ((jsonObj.get("calling_code") != null && !jsonObj.get("calling_code").isJsonNull()) && !jsonObj.get("calling_code").isJsonPrimitive()) {
|
|
throw new IllegalArgumentException(String.format("Expected the field `calling_code` to be a primitive type in the JSON string but got `%s`", jsonObj.get("calling_code").toString()));
|
|
}
|
|
if ((jsonObj.get("tld") != null && !jsonObj.get("tld").isJsonNull()) && !jsonObj.get("tld").isJsonPrimitive()) {
|
|
throw new IllegalArgumentException(String.format("Expected the field `tld` to be a primitive type in the JSON string but got `%s`", jsonObj.get("tld").toString()));
|
|
}
|
|
if ((jsonObj.get("language") != null && !jsonObj.get("language").isJsonNull()) && !jsonObj.get("language").isJsonPrimitive()) {
|
|
throw new IllegalArgumentException(String.format("Expected the field `language` to be a primitive type in the JSON string but got `%s`", jsonObj.get("language").toString()));
|
|
}
|
|
if ((jsonObj.get("timezone") != null && !jsonObj.get("timezone").isJsonNull()) && !jsonObj.get("timezone").isJsonPrimitive()) {
|
|
throw new IllegalArgumentException(String.format("Expected the field `timezone` to be a primitive type in the JSON string but got `%s`", jsonObj.get("timezone").toString()));
|
|
}
|
|
if ((jsonObj.get("currency") != null && !jsonObj.get("currency").isJsonNull()) && !jsonObj.get("currency").isJsonPrimitive()) {
|
|
throw new IllegalArgumentException(String.format("Expected the field `currency` to be a primitive type in the JSON string but got `%s`", jsonObj.get("currency").toString()));
|
|
}
|
|
}
|
|
|
|
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
|
|
@SuppressWarnings("unchecked")
|
|
@Override
|
|
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
|
|
if (!IpAddress.class.isAssignableFrom(type.getRawType())) {
|
|
return null; // this class only serializes 'IpAddress' and its subtypes
|
|
}
|
|
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
|
|
final TypeAdapter<IpAddress> thisAdapter
|
|
= gson.getDelegateAdapter(this, TypeToken.get(IpAddress.class));
|
|
|
|
return (TypeAdapter<T>) new TypeAdapter<IpAddress>() {
|
|
@Override
|
|
public void write(JsonWriter out, IpAddress value) throws IOException {
|
|
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
|
|
elementAdapter.write(out, obj);
|
|
}
|
|
|
|
@Override
|
|
public IpAddress read(JsonReader in) throws IOException {
|
|
JsonElement jsonElement = elementAdapter.read(in);
|
|
validateJsonElement(jsonElement);
|
|
return thisAdapter.fromJsonTree(jsonElement);
|
|
}
|
|
|
|
}.nullSafe();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Create an instance of IpAddress given an JSON string
|
|
*
|
|
* @param jsonString JSON string
|
|
* @return An instance of IpAddress
|
|
* @throws IOException if the JSON string is invalid with respect to IpAddress
|
|
*/
|
|
public static IpAddress fromJson(String jsonString) throws IOException {
|
|
return JSON.getGson().fromJson(jsonString, IpAddress.class);
|
|
}
|
|
|
|
/**
|
|
* Convert an instance of IpAddress to an JSON string
|
|
*
|
|
* @return JSON string
|
|
*/
|
|
public String toJson() {
|
|
return JSON.getGson().toJson(this);
|
|
}
|
|
}
|
|
|