|
| 1 | +/* |
| 2 | + * EMService |
| 3 | + * Easemob Rest API |
| 4 | + * |
| 5 | + * The version of the OpenAPI document: 1.0.0 |
| 6 | + * |
| 7 | + * |
| 8 | + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). |
| 9 | + * https://openapi-generator.tech |
| 10 | + * Do not edit the class manually. |
| 11 | + */ |
| 12 | + |
| 13 | + |
| 14 | +package com.easemob.im.api.model; |
| 15 | + |
| 16 | +import com.easemob.im.JSON; |
| 17 | +import com.google.gson.*; |
| 18 | +import com.google.gson.annotations.SerializedName; |
| 19 | +import com.google.gson.reflect.TypeToken; |
| 20 | +import com.google.gson.stream.JsonReader; |
| 21 | +import com.google.gson.stream.JsonWriter; |
| 22 | + |
| 23 | +import java.io.IOException; |
| 24 | +import java.util.HashSet; |
| 25 | +import java.util.Map; |
| 26 | +import java.util.Objects; |
| 27 | +import java.util.Set; |
| 28 | + |
| 29 | +/** |
| 30 | + * EMBatchCustomGroupMemberAttribute |
| 31 | + */ |
| 32 | +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2024-11-20T11:16:55.650302+08:00[Asia/Shanghai]") |
| 33 | +public class EMBatchCustomGroupMemberAttribute { |
| 34 | + public static final String SERIALIZED_NAME_USERNAME = "username"; |
| 35 | + @SerializedName(SERIALIZED_NAME_USERNAME) |
| 36 | + private String username; |
| 37 | + |
| 38 | + public static final String SERIALIZED_NAME_METADATA = "metadata"; |
| 39 | + @SerializedName(SERIALIZED_NAME_METADATA) |
| 40 | + private Object metadata; |
| 41 | + |
| 42 | + public EMBatchCustomGroupMemberAttribute() { |
| 43 | + } |
| 44 | + |
| 45 | + public EMBatchCustomGroupMemberAttribute username(String username) { |
| 46 | + |
| 47 | + this.username = username; |
| 48 | + return this; |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * 用户 ID,长度不可超过 64 字节 |
| 53 | + * @return username |
| 54 | + **/ |
| 55 | + @javax.annotation.Nullable |
| 56 | + public String getUsername() { |
| 57 | + return username; |
| 58 | + } |
| 59 | + |
| 60 | + |
| 61 | + public void setUsername(String username) { |
| 62 | + this.username = username; |
| 63 | + } |
| 64 | + |
| 65 | + |
| 66 | + public EMBatchCustomGroupMemberAttribute metadata(Object metadata) { |
| 67 | + |
| 68 | + this.metadata = metadata; |
| 69 | + return this; |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * 要设置的群成员自定义属性,为 key-value 键值对。对于单个键值对: - key 表示属性名称,不能超过 16 字节。 - value 表示属性值,不能超过 512 个字节。若 value 设置为空字符串即删除该自定义属性。 单个群成员的自定义属性总长度不能超过 4 KB |
| 74 | + * @return metadata |
| 75 | + **/ |
| 76 | + @javax.annotation.Nullable |
| 77 | + public Object getMetadata() { |
| 78 | + return metadata; |
| 79 | + } |
| 80 | + |
| 81 | + |
| 82 | + public void setMetadata(Object metadata) { |
| 83 | + this.metadata = metadata; |
| 84 | + } |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | + @Override |
| 89 | + public boolean equals(Object o) { |
| 90 | + if (this == o) { |
| 91 | + return true; |
| 92 | + } |
| 93 | + if (o == null || getClass() != o.getClass()) { |
| 94 | + return false; |
| 95 | + } |
| 96 | + EMBatchCustomGroupMemberAttribute batchCustomGroupMemberAttribute = (EMBatchCustomGroupMemberAttribute) o; |
| 97 | + return Objects.equals(this.username, batchCustomGroupMemberAttribute.username) && |
| 98 | + Objects.equals(this.metadata, batchCustomGroupMemberAttribute.metadata); |
| 99 | + } |
| 100 | + |
| 101 | + @Override |
| 102 | + public int hashCode() { |
| 103 | + return Objects.hash(username, metadata); |
| 104 | + } |
| 105 | + |
| 106 | + @Override |
| 107 | + public String toString() { |
| 108 | + StringBuilder sb = new StringBuilder(); |
| 109 | + sb.append("class EMBatchCustomGroupMemberAttribute {\n"); |
| 110 | + sb.append(" username: ").append(toIndentedString(username)).append("\n"); |
| 111 | + sb.append(" metadata: ").append(toIndentedString(metadata)).append("\n"); |
| 112 | + sb.append("}"); |
| 113 | + return sb.toString(); |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * Convert the given object to string with each line indented by 4 spaces |
| 118 | + * (except the first line). |
| 119 | + */ |
| 120 | + private String toIndentedString(Object o) { |
| 121 | + if (o == null) { |
| 122 | + return "null"; |
| 123 | + } |
| 124 | + return o.toString().replace("\n", "\n "); |
| 125 | + } |
| 126 | + |
| 127 | + |
| 128 | + public static HashSet<String> openapiFields; |
| 129 | + public static HashSet<String> openapiRequiredFields; |
| 130 | + |
| 131 | + static { |
| 132 | + // a set of all properties/fields (JSON key names) |
| 133 | + openapiFields = new HashSet<String>(); |
| 134 | + openapiFields.add("username"); |
| 135 | + openapiFields.add("metadata"); |
| 136 | + |
| 137 | + // a set of required properties/fields (JSON key names) |
| 138 | + openapiRequiredFields = new HashSet<String>(); |
| 139 | + } |
| 140 | + |
| 141 | + /** |
| 142 | + * Validates the JSON Element and throws an exception if issues found |
| 143 | + * |
| 144 | + * @param jsonElement JSON Element |
| 145 | + * @throws IOException if the JSON Element is invalid with respect to EMBatchCustomGroupMemberAttribute |
| 146 | + */ |
| 147 | + public static void validateJsonElement(JsonElement jsonElement) throws IOException { |
| 148 | + if (jsonElement == null) { |
| 149 | + if (!EMBatchCustomGroupMemberAttribute.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null |
| 150 | + throw new IllegalArgumentException(String.format("The required field(s) %s in EMBatchCustomGroupMemberAttribute is not found in the empty JSON string", EMBatchCustomGroupMemberAttribute.openapiRequiredFields.toString())); |
| 151 | + } |
| 152 | + } |
| 153 | + |
| 154 | + Set<Map.Entry<String, JsonElement>> entries = jsonElement.getAsJsonObject().entrySet(); |
| 155 | + // check to see if the JSON string contains additional fields |
| 156 | + for (Map.Entry<String, JsonElement> entry : entries) { |
| 157 | + if (!EMBatchCustomGroupMemberAttribute.openapiFields.contains(entry.getKey())) { |
| 158 | + throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `EMBatchCustomGroupMemberAttribute` properties. JSON: %s", entry.getKey(), jsonElement.toString())); |
| 159 | + } |
| 160 | + } |
| 161 | + JsonObject jsonObj = jsonElement.getAsJsonObject(); |
| 162 | + if ((jsonObj.get("username") != null && !jsonObj.get("username").isJsonNull()) && !jsonObj.get("username").isJsonPrimitive()) { |
| 163 | + throw new IllegalArgumentException(String.format("Expected the field `username` to be a primitive type in the JSON string but got `%s`", jsonObj.get("username").toString())); |
| 164 | + } |
| 165 | + } |
| 166 | + |
| 167 | + public static class CustomTypeAdapterFactory implements TypeAdapterFactory { |
| 168 | + @SuppressWarnings("unchecked") |
| 169 | + @Override |
| 170 | + public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) { |
| 171 | + if (!EMBatchCustomGroupMemberAttribute.class.isAssignableFrom(type.getRawType())) { |
| 172 | + return null; // this class only serializes 'EMBatchCustomGroupMemberAttribute' and its subtypes |
| 173 | + } |
| 174 | + final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class); |
| 175 | + final TypeAdapter<EMBatchCustomGroupMemberAttribute> thisAdapter |
| 176 | + = gson.getDelegateAdapter(this, TypeToken.get(EMBatchCustomGroupMemberAttribute.class)); |
| 177 | + |
| 178 | + return (TypeAdapter<T>) new TypeAdapter<EMBatchCustomGroupMemberAttribute>() { |
| 179 | + @Override |
| 180 | + public void write(JsonWriter out, EMBatchCustomGroupMemberAttribute value) throws IOException { |
| 181 | + JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); |
| 182 | + elementAdapter.write(out, obj); |
| 183 | + } |
| 184 | + |
| 185 | + @Override |
| 186 | + public EMBatchCustomGroupMemberAttribute read(JsonReader in) throws IOException { |
| 187 | + JsonElement jsonElement = elementAdapter.read(in); |
| 188 | + validateJsonElement(jsonElement); |
| 189 | + return thisAdapter.fromJsonTree(jsonElement); |
| 190 | + } |
| 191 | + |
| 192 | + }.nullSafe(); |
| 193 | + } |
| 194 | + } |
| 195 | + |
| 196 | + /** |
| 197 | + * Create an instance of EMBatchCustomGroupMemberAttribute given an JSON string |
| 198 | + * |
| 199 | + * @param jsonString JSON string |
| 200 | + * @return An instance of EMBatchCustomGroupMemberAttribute |
| 201 | + * @throws IOException if the JSON string is invalid with respect to EMBatchCustomGroupMemberAttribute |
| 202 | + */ |
| 203 | + public static EMBatchCustomGroupMemberAttribute fromJson(String jsonString) throws IOException { |
| 204 | + return JSON.getGson().fromJson(jsonString, EMBatchCustomGroupMemberAttribute.class); |
| 205 | + } |
| 206 | + |
| 207 | + /** |
| 208 | + * Convert an instance of EMBatchCustomGroupMemberAttribute to an JSON string |
| 209 | + * |
| 210 | + * @return JSON string |
| 211 | + */ |
| 212 | + public String toJson() { |
| 213 | + return JSON.getGson().toJson(this); |
| 214 | + } |
| 215 | +} |
| 216 | + |
0 commit comments