|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +package io.clientcore.annotation.processor.test.implementation; |
| 5 | + |
| 6 | +import io.clientcore.core.serialization.json.JsonReader; |
| 7 | +import io.clientcore.core.serialization.json.JsonSerializable; |
| 8 | +import io.clientcore.core.serialization.json.JsonToken; |
| 9 | +import io.clientcore.core.serialization.json.JsonWriter; |
| 10 | + |
| 11 | +import java.io.IOException; |
| 12 | +import java.time.OffsetDateTime; |
| 13 | +import java.time.format.DateTimeFormatter; |
| 14 | +import java.util.Map; |
| 15 | + |
| 16 | +/** |
| 17 | + * The Foo model. |
| 18 | + */ |
| 19 | +public final class Foo implements JsonSerializable<Foo> { |
| 20 | + /* |
| 21 | + * The key of the key-value. |
| 22 | + */ |
| 23 | + private String key; |
| 24 | + |
| 25 | + /* |
| 26 | + * The label the key-value belongs to. |
| 27 | + */ |
| 28 | + private String label; |
| 29 | + |
| 30 | + /* |
| 31 | + * The content type of the value stored within the key-value. |
| 32 | + */ |
| 33 | + private String contentType; |
| 34 | + |
| 35 | + /* |
| 36 | + * The value of the key-value. |
| 37 | + */ |
| 38 | + private String value; |
| 39 | + |
| 40 | + /* |
| 41 | + * A date representing the last time the key-value was modified. |
| 42 | + */ |
| 43 | + private OffsetDateTime lastModified; |
| 44 | + |
| 45 | + /* |
| 46 | + * The tags of the key-value |
| 47 | + */ |
| 48 | + private Map<String, String> tags; |
| 49 | + |
| 50 | + /* |
| 51 | + * Indicates whether the key-value is locked. |
| 52 | + */ |
| 53 | + private Boolean locked; |
| 54 | + |
| 55 | + /* |
| 56 | + * A value representing the current state of the resource. |
| 57 | + */ |
| 58 | + private String etag; |
| 59 | + |
| 60 | + /** |
| 61 | + * Creates an instance of Foo class. |
| 62 | + */ |
| 63 | + public Foo() { |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Get the key property: The key of the key-value. |
| 68 | + * |
| 69 | + * @return the key value. |
| 70 | + */ |
| 71 | + public String getKey() { |
| 72 | + return this.key; |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * Set the key property: The key of the key-value. |
| 77 | + * |
| 78 | + * @param key the key value to set. |
| 79 | + * @return the Foo object itself. |
| 80 | + */ |
| 81 | + public Foo setKey(String key) { |
| 82 | + this.key = key; |
| 83 | + return this; |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * Get the label property: The label the key-value belongs to. |
| 88 | + * |
| 89 | + * @return the label value. |
| 90 | + */ |
| 91 | + public String getLabel() { |
| 92 | + return this.label; |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * Set the label property: The label the key-value belongs to. |
| 97 | + * |
| 98 | + * @param label the label value to set. |
| 99 | + * @return the Foo object itself. |
| 100 | + */ |
| 101 | + public Foo setLabel(String label) { |
| 102 | + this.label = label; |
| 103 | + return this; |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * Get the contentType property: The content type of the value stored within the key-value. |
| 108 | + * |
| 109 | + * @return the contentType value. |
| 110 | + */ |
| 111 | + public String getContentType() { |
| 112 | + return this.contentType; |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * Set the contentType property: The content type of the value stored within the key-value. |
| 117 | + * |
| 118 | + * @param contentType the contentType value to set. |
| 119 | + * @return the Foo object itself. |
| 120 | + */ |
| 121 | + public Foo setContentType(String contentType) { |
| 122 | + this.contentType = contentType; |
| 123 | + return this; |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * Get the value property: The value of the key-value. |
| 128 | + * |
| 129 | + * @return the value value. |
| 130 | + */ |
| 131 | + public String getValue() { |
| 132 | + return this.value; |
| 133 | + } |
| 134 | + |
| 135 | + /** |
| 136 | + * Set the value property: The value of the key-value. |
| 137 | + * |
| 138 | + * @param value the value value to set. |
| 139 | + * @return the Foo object itself. |
| 140 | + */ |
| 141 | + public Foo setValue(String value) { |
| 142 | + this.value = value; |
| 143 | + return this; |
| 144 | + } |
| 145 | + |
| 146 | + /** |
| 147 | + * Get the lastModified property: A date representing the last time the key-value was modified. |
| 148 | + * |
| 149 | + * @return the lastModified value. |
| 150 | + */ |
| 151 | + public OffsetDateTime getLastModified() { |
| 152 | + return this.lastModified; |
| 153 | + } |
| 154 | + |
| 155 | + /** |
| 156 | + * Set the lastModified property: A date representing the last time the key-value was modified. |
| 157 | + * |
| 158 | + * @param lastModified the lastModified value to set. |
| 159 | + * @return the Foo object itself. |
| 160 | + */ |
| 161 | + public Foo setLastModified(OffsetDateTime lastModified) { |
| 162 | + this.lastModified = lastModified; |
| 163 | + return this; |
| 164 | + } |
| 165 | + |
| 166 | + /** |
| 167 | + * Get the tags property: The tags of the key-value. |
| 168 | + * |
| 169 | + * @return the tags value. |
| 170 | + */ |
| 171 | + public Map<String, String> getTags() { |
| 172 | + return this.tags; |
| 173 | + } |
| 174 | + |
| 175 | + /** |
| 176 | + * Set the tags property: The tags of the key-value. |
| 177 | + * |
| 178 | + * @param tags the tags value to set. |
| 179 | + * @return the Foo object itself. |
| 180 | + */ |
| 181 | + public Foo setTags(Map<String, String> tags) { |
| 182 | + this.tags = tags; |
| 183 | + return this; |
| 184 | + } |
| 185 | + |
| 186 | + /** |
| 187 | + * Get the locked property: Indicates whether the key-value is locked. |
| 188 | + * |
| 189 | + * @return the locked value. |
| 190 | + */ |
| 191 | + public Boolean isLocked() { |
| 192 | + return this.locked; |
| 193 | + } |
| 194 | + |
| 195 | + /** |
| 196 | + * Set the locked property: Indicates whether the key-value is locked. |
| 197 | + * |
| 198 | + * @param locked the locked value to set. |
| 199 | + * @return the Foo object itself. |
| 200 | + */ |
| 201 | + public Foo setLocked(Boolean locked) { |
| 202 | + this.locked = locked; |
| 203 | + return this; |
| 204 | + } |
| 205 | + |
| 206 | + /** |
| 207 | + * Get the etag property: A value representing the current state of the resource. |
| 208 | + * |
| 209 | + * @return the etag value. |
| 210 | + */ |
| 211 | + public String getEtag() { |
| 212 | + return this.etag; |
| 213 | + } |
| 214 | + |
| 215 | + /** |
| 216 | + * Set the etag property: A value representing the current state of the resource. |
| 217 | + * |
| 218 | + * @param etag the etag value to set. |
| 219 | + * @return the Foo object itself. |
| 220 | + */ |
| 221 | + public Foo setEtag(String etag) { |
| 222 | + this.etag = etag; |
| 223 | + return this; |
| 224 | + } |
| 225 | + |
| 226 | + /** |
| 227 | + * {@inheritDoc} |
| 228 | + */ |
| 229 | + @Override |
| 230 | + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { |
| 231 | + jsonWriter.writeStartObject(); |
| 232 | + jsonWriter.writeStringField("key", this.key); |
| 233 | + jsonWriter.writeStringField("label", this.label); |
| 234 | + jsonWriter.writeStringField("content_type", this.contentType); |
| 235 | + jsonWriter.writeStringField("value", this.value); |
| 236 | + jsonWriter.writeStringField("last_modified", |
| 237 | + this.lastModified == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.lastModified)); |
| 238 | + jsonWriter.writeMapField("tags", this.tags, (writer, element) -> writer.writeString(element)); |
| 239 | + jsonWriter.writeBooleanField("locked", this.locked); |
| 240 | + jsonWriter.writeStringField("etag", this.etag); |
| 241 | + return jsonWriter.writeEndObject(); |
| 242 | + } |
| 243 | + |
| 244 | + /** |
| 245 | + * Reads an instance of Foo from the JsonReader. |
| 246 | + * |
| 247 | + * @param jsonReader The JsonReader being read. |
| 248 | + * @return An instance of Foo if the JsonReader was pointing to an instance of it, or null if it was pointing |
| 249 | + * to JSON null. |
| 250 | + * @throws IOException If an error occurs while reading the Foo. |
| 251 | + */ |
| 252 | + public static Foo fromJson(JsonReader jsonReader) throws IOException { |
| 253 | + return jsonReader.readObject(reader -> { |
| 254 | + Foo deserializedKeyValue = new Foo(); |
| 255 | + while (reader.nextToken() != JsonToken.END_OBJECT) { |
| 256 | + String fieldName = reader.getFieldName(); |
| 257 | + reader.nextToken(); |
| 258 | + |
| 259 | + if ("key".equals(fieldName)) { |
| 260 | + deserializedKeyValue.key = reader.getString(); |
| 261 | + } else if ("label".equals(fieldName)) { |
| 262 | + deserializedKeyValue.label = reader.getString(); |
| 263 | + } else if ("content_type".equals(fieldName)) { |
| 264 | + deserializedKeyValue.contentType = reader.getString(); |
| 265 | + } else if ("value".equals(fieldName)) { |
| 266 | + deserializedKeyValue.value = reader.getString(); |
| 267 | + } else if ("last_modified".equals(fieldName)) { |
| 268 | + deserializedKeyValue.lastModified = OffsetDateTime.parse(reader.getString()); |
| 269 | + } else if ("tags".equals(fieldName)) { |
| 270 | + Map<String, String> tags = reader.readMap(reader1 -> reader1.getString()); |
| 271 | + deserializedKeyValue.tags = tags; |
| 272 | + } else if ("locked".equals(fieldName)) { |
| 273 | + deserializedKeyValue.locked = reader.getNullable(JsonReader::getBoolean); |
| 274 | + } else if ("etag".equals(fieldName)) { |
| 275 | + deserializedKeyValue.etag = reader.getString(); |
| 276 | + } else { |
| 277 | + reader.skipChildren(); |
| 278 | + } |
| 279 | + } |
| 280 | + |
| 281 | + return deserializedKeyValue; |
| 282 | + }); |
| 283 | + } |
| 284 | +} |
0 commit comments