|
| 1 | +/* |
| 2 | + * Segment Public API |
| 3 | + * The Segment Public API helps you manage your Segment Workspaces and its resources. You can use the API to perform CRUD (create, read, update, delete) operations at no extra charge. This includes working with resources such as Sources, Destinations, Warehouses, Tracking Plans, and the Segment Destinations and Sources Catalogs. All CRUD endpoints in the API follow REST conventions and use standard HTTP methods. Different URL endpoints represent different resources in a Workspace. See the next sections for more information on how to use the Segment Public API. |
| 4 | + * |
| 5 | + |
| 6 | + * |
| 7 | + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). |
| 8 | + * https://openapi-generator.tech |
| 9 | + * Do not edit the class manually. |
| 10 | + */ |
| 11 | + |
| 12 | +package com.segment.publicapi.models; |
| 13 | + |
| 14 | +import com.google.gson.Gson; |
| 15 | +import com.google.gson.JsonElement; |
| 16 | +import com.google.gson.JsonObject; |
| 17 | +import com.google.gson.TypeAdapter; |
| 18 | +import com.google.gson.TypeAdapterFactory; |
| 19 | +import com.google.gson.annotations.SerializedName; |
| 20 | +import com.google.gson.reflect.TypeToken; |
| 21 | +import com.google.gson.stream.JsonReader; |
| 22 | +import com.google.gson.stream.JsonWriter; |
| 23 | +import com.segment.publicapi.JSON; |
| 24 | +import java.io.IOException; |
| 25 | +import java.util.HashSet; |
| 26 | +import java.util.Map; |
| 27 | +import java.util.Objects; |
| 28 | +import java.util.Set; |
| 29 | + |
| 30 | +/** Result membership object for an audience preview with `audienceType: ACCOUNTS`. */ |
| 31 | +public class AudiencePreviewAccountResult { |
| 32 | + public static final String SERIALIZED_NAME_ID = "id"; |
| 33 | + |
| 34 | + @SerializedName(SERIALIZED_NAME_ID) |
| 35 | + private String id; |
| 36 | + |
| 37 | + public AudiencePreviewAccountResult() {} |
| 38 | + |
| 39 | + public AudiencePreviewAccountResult id(String id) { |
| 40 | + |
| 41 | + this.id = id; |
| 42 | + return this; |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Account id. |
| 47 | + * |
| 48 | + * @return id |
| 49 | + */ |
| 50 | + @javax.annotation.Nonnull |
| 51 | + public String getId() { |
| 52 | + return id; |
| 53 | + } |
| 54 | + |
| 55 | + public void setId(String id) { |
| 56 | + this.id = id; |
| 57 | + } |
| 58 | + |
| 59 | + @Override |
| 60 | + public boolean equals(Object o) { |
| 61 | + if (this == o) { |
| 62 | + return true; |
| 63 | + } |
| 64 | + if (o == null || getClass() != o.getClass()) { |
| 65 | + return false; |
| 66 | + } |
| 67 | + AudiencePreviewAccountResult audiencePreviewAccountResult = |
| 68 | + (AudiencePreviewAccountResult) o; |
| 69 | + return Objects.equals(this.id, audiencePreviewAccountResult.id); |
| 70 | + } |
| 71 | + |
| 72 | + @Override |
| 73 | + public int hashCode() { |
| 74 | + return Objects.hash(id); |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + public String toString() { |
| 79 | + StringBuilder sb = new StringBuilder(); |
| 80 | + sb.append("class AudiencePreviewAccountResult {\n"); |
| 81 | + sb.append(" id: ").append(toIndentedString(id)).append("\n"); |
| 82 | + sb.append("}"); |
| 83 | + return sb.toString(); |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * Convert the given object to string with each line indented by 4 spaces (except the first |
| 88 | + * line). |
| 89 | + */ |
| 90 | + private String toIndentedString(Object o) { |
| 91 | + if (o == null) { |
| 92 | + return "null"; |
| 93 | + } |
| 94 | + return o.toString().replace("\n", "\n "); |
| 95 | + } |
| 96 | + |
| 97 | + public static HashSet<String> openapiFields; |
| 98 | + public static HashSet<String> openapiRequiredFields; |
| 99 | + |
| 100 | + static { |
| 101 | + // a set of all properties/fields (JSON key names) |
| 102 | + openapiFields = new HashSet<String>(); |
| 103 | + openapiFields.add("id"); |
| 104 | + |
| 105 | + // a set of required properties/fields (JSON key names) |
| 106 | + openapiRequiredFields = new HashSet<String>(); |
| 107 | + openapiRequiredFields.add("id"); |
| 108 | + } |
| 109 | + |
| 110 | + /** |
| 111 | + * Validates the JSON Element and throws an exception if issues found |
| 112 | + * |
| 113 | + * @param jsonElement JSON Element |
| 114 | + * @throws IOException if the JSON Element is invalid with respect to |
| 115 | + * AudiencePreviewAccountResult |
| 116 | + */ |
| 117 | + public static void validateJsonElement(JsonElement jsonElement) throws IOException { |
| 118 | + if (jsonElement == null) { |
| 119 | + if (!AudiencePreviewAccountResult.openapiRequiredFields |
| 120 | + .isEmpty()) { // has required fields but JSON element is null |
| 121 | + throw new IllegalArgumentException( |
| 122 | + String.format( |
| 123 | + "The required field(s) %s in AudiencePreviewAccountResult is not" |
| 124 | + + " found in the empty JSON string", |
| 125 | + AudiencePreviewAccountResult.openapiRequiredFields.toString())); |
| 126 | + } |
| 127 | + } |
| 128 | + |
| 129 | + Set<Map.Entry<String, JsonElement>> entries = jsonElement.getAsJsonObject().entrySet(); |
| 130 | + // check to see if the JSON string contains additional fields |
| 131 | + for (Map.Entry<String, JsonElement> entry : entries) { |
| 132 | + if (!AudiencePreviewAccountResult.openapiFields.contains(entry.getKey())) { |
| 133 | + throw new IllegalArgumentException( |
| 134 | + String.format( |
| 135 | + "The field `%s` in the JSON string is not defined in the" |
| 136 | + + " `AudiencePreviewAccountResult` properties. JSON: %s", |
| 137 | + entry.getKey(), jsonElement.toString())); |
| 138 | + } |
| 139 | + } |
| 140 | + |
| 141 | + // check to make sure all required properties/fields are present in the JSON string |
| 142 | + for (String requiredField : AudiencePreviewAccountResult.openapiRequiredFields) { |
| 143 | + if (jsonElement.getAsJsonObject().get(requiredField) == null) { |
| 144 | + throw new IllegalArgumentException( |
| 145 | + String.format( |
| 146 | + "The required field `%s` is not found in the JSON string: %s", |
| 147 | + requiredField, jsonElement.toString())); |
| 148 | + } |
| 149 | + } |
| 150 | + JsonObject jsonObj = jsonElement.getAsJsonObject(); |
| 151 | + if (!jsonObj.get("id").isJsonPrimitive()) { |
| 152 | + throw new IllegalArgumentException( |
| 153 | + String.format( |
| 154 | + "Expected the field `id` to be a primitive type in the JSON string but" |
| 155 | + + " got `%s`", |
| 156 | + jsonObj.get("id").toString())); |
| 157 | + } |
| 158 | + } |
| 159 | + |
| 160 | + public static class CustomTypeAdapterFactory implements TypeAdapterFactory { |
| 161 | + @SuppressWarnings("unchecked") |
| 162 | + @Override |
| 163 | + public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) { |
| 164 | + if (!AudiencePreviewAccountResult.class.isAssignableFrom(type.getRawType())) { |
| 165 | + return null; // this class only serializes 'AudiencePreviewAccountResult' and its |
| 166 | + // subtypes |
| 167 | + } |
| 168 | + final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class); |
| 169 | + final TypeAdapter<AudiencePreviewAccountResult> thisAdapter = |
| 170 | + gson.getDelegateAdapter( |
| 171 | + this, TypeToken.get(AudiencePreviewAccountResult.class)); |
| 172 | + |
| 173 | + return (TypeAdapter<T>) |
| 174 | + new TypeAdapter<AudiencePreviewAccountResult>() { |
| 175 | + @Override |
| 176 | + public void write(JsonWriter out, AudiencePreviewAccountResult value) |
| 177 | + throws IOException { |
| 178 | + JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); |
| 179 | + elementAdapter.write(out, obj); |
| 180 | + } |
| 181 | + |
| 182 | + @Override |
| 183 | + public AudiencePreviewAccountResult read(JsonReader in) throws IOException { |
| 184 | + JsonElement jsonElement = elementAdapter.read(in); |
| 185 | + validateJsonElement(jsonElement); |
| 186 | + return thisAdapter.fromJsonTree(jsonElement); |
| 187 | + } |
| 188 | + }.nullSafe(); |
| 189 | + } |
| 190 | + } |
| 191 | + |
| 192 | + /** |
| 193 | + * Create an instance of AudiencePreviewAccountResult given an JSON string |
| 194 | + * |
| 195 | + * @param jsonString JSON string |
| 196 | + * @return An instance of AudiencePreviewAccountResult |
| 197 | + * @throws IOException if the JSON string is invalid with respect to |
| 198 | + * AudiencePreviewAccountResult |
| 199 | + */ |
| 200 | + public static AudiencePreviewAccountResult fromJson(String jsonString) throws IOException { |
| 201 | + return JSON.getGson().fromJson(jsonString, AudiencePreviewAccountResult.class); |
| 202 | + } |
| 203 | + |
| 204 | + /** |
| 205 | + * Convert an instance of AudiencePreviewAccountResult to an JSON string |
| 206 | + * |
| 207 | + * @return JSON string |
| 208 | + */ |
| 209 | + public String toJson() { |
| 210 | + return JSON.getGson().toJson(this); |
| 211 | + } |
| 212 | +} |
0 commit comments