|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | +// Code generated by Microsoft (R) TypeSpec Code Generator. |
| 4 | + |
| 5 | +package com.azure.ai.translation.text.models; |
| 6 | + |
| 7 | +import com.azure.core.annotation.Fluent; |
| 8 | +import com.azure.core.annotation.Generated; |
| 9 | +import com.azure.json.JsonReader; |
| 10 | +import com.azure.json.JsonSerializable; |
| 11 | +import com.azure.json.JsonToken; |
| 12 | +import com.azure.json.JsonWriter; |
| 13 | +import java.io.IOException; |
| 14 | +import java.util.List; |
| 15 | + |
| 16 | +/** |
| 17 | + * Request body parameters for the translate API. |
| 18 | + */ |
| 19 | +@Fluent |
| 20 | +public final class TranslateBodyDetails implements JsonSerializable<TranslateBodyDetails> { |
| 21 | + /* |
| 22 | + * Specifies the text string to be translated in the translate API. |
| 23 | + */ |
| 24 | + @Generated |
| 25 | + private final String text; |
| 26 | + |
| 27 | + /* |
| 28 | + * Specifies the script of the input text. |
| 29 | + */ |
| 30 | + @Generated |
| 31 | + private String script; |
| 32 | + |
| 33 | + /* |
| 34 | + * Specifies the language of the input text. Find which languages are available to translate by |
| 35 | + * looking up supported languages using the translation scope. If the language parameter isn't |
| 36 | + * specified, automatic language detection is applied to determine the source language. |
| 37 | + * |
| 38 | + * You must use the language parameter rather than autodetection when using the dynamic dictionary feature. |
| 39 | + * Note: the dynamic dictionary feature is case-sensitive. |
| 40 | + */ |
| 41 | + @Generated |
| 42 | + private String language; |
| 43 | + |
| 44 | + /* |
| 45 | + * Defines whether the text being translated is plain text or HTML text. Any HTML needs to be a well-formed, |
| 46 | + * complete element. Possible values are: plain (default) or html. |
| 47 | + */ |
| 48 | + @Generated |
| 49 | + private TextType textType; |
| 50 | + |
| 51 | + /* |
| 52 | + * Translation target parameters. |
| 53 | + */ |
| 54 | + @Generated |
| 55 | + private final List<TranslateTarget> targets; |
| 56 | + |
| 57 | + /** |
| 58 | + * Creates an instance of TranslateBodyDetails class. |
| 59 | + * |
| 60 | + * @param text the text value to set. |
| 61 | + * @param targets the targets value to set. |
| 62 | + */ |
| 63 | + @Generated |
| 64 | + public TranslateBodyDetails(String text, List<TranslateTarget> targets) { |
| 65 | + this.text = text; |
| 66 | + this.targets = targets; |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Get the text property: Specifies the text string to be translated in the translate API. |
| 71 | + * |
| 72 | + * @return the text value. |
| 73 | + */ |
| 74 | + @Generated |
| 75 | + public String getText() { |
| 76 | + return this.text; |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * Get the script property: Specifies the script of the input text. |
| 81 | + * |
| 82 | + * @return the script value. |
| 83 | + */ |
| 84 | + @Generated |
| 85 | + public String getScript() { |
| 86 | + return this.script; |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * Set the script property: Specifies the script of the input text. |
| 91 | + * |
| 92 | + * @param script the script value to set. |
| 93 | + * @return the TranslateBodyDetails object itself. |
| 94 | + */ |
| 95 | + @Generated |
| 96 | + public TranslateBodyDetails setScript(String script) { |
| 97 | + this.script = script; |
| 98 | + return this; |
| 99 | + } |
| 100 | + |
| 101 | + /** |
| 102 | + * Get the language property: Specifies the language of the input text. Find which languages are available to |
| 103 | + * translate by |
| 104 | + * looking up supported languages using the translation scope. If the language parameter isn't |
| 105 | + * specified, automatic language detection is applied to determine the source language. |
| 106 | + * |
| 107 | + * You must use the language parameter rather than autodetection when using the dynamic dictionary feature. |
| 108 | + * Note: the dynamic dictionary feature is case-sensitive. |
| 109 | + * |
| 110 | + * @return the language value. |
| 111 | + */ |
| 112 | + @Generated |
| 113 | + public String getLanguage() { |
| 114 | + return this.language; |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * Set the language property: Specifies the language of the input text. Find which languages are available to |
| 119 | + * translate by |
| 120 | + * looking up supported languages using the translation scope. If the language parameter isn't |
| 121 | + * specified, automatic language detection is applied to determine the source language. |
| 122 | + * |
| 123 | + * You must use the language parameter rather than autodetection when using the dynamic dictionary feature. |
| 124 | + * Note: the dynamic dictionary feature is case-sensitive. |
| 125 | + * |
| 126 | + * @param language the language value to set. |
| 127 | + * @return the TranslateBodyDetails object itself. |
| 128 | + */ |
| 129 | + @Generated |
| 130 | + public TranslateBodyDetails setLanguage(String language) { |
| 131 | + this.language = language; |
| 132 | + return this; |
| 133 | + } |
| 134 | + |
| 135 | + /** |
| 136 | + * Get the textType property: Defines whether the text being translated is plain text or HTML text. Any HTML needs |
| 137 | + * to be a well-formed, |
| 138 | + * complete element. Possible values are: plain (default) or html. |
| 139 | + * |
| 140 | + * @return the textType value. |
| 141 | + */ |
| 142 | + @Generated |
| 143 | + public TextType getTextType() { |
| 144 | + return this.textType; |
| 145 | + } |
| 146 | + |
| 147 | + /** |
| 148 | + * Set the textType property: Defines whether the text being translated is plain text or HTML text. Any HTML needs |
| 149 | + * to be a well-formed, |
| 150 | + * complete element. Possible values are: plain (default) or html. |
| 151 | + * |
| 152 | + * @param textType the textType value to set. |
| 153 | + * @return the TranslateBodyDetails object itself. |
| 154 | + */ |
| 155 | + @Generated |
| 156 | + public TranslateBodyDetails setTextType(TextType textType) { |
| 157 | + this.textType = textType; |
| 158 | + return this; |
| 159 | + } |
| 160 | + |
| 161 | + /** |
| 162 | + * Get the targets property: Translation target parameters. |
| 163 | + * |
| 164 | + * @return the targets value. |
| 165 | + */ |
| 166 | + @Generated |
| 167 | + public List<TranslateTarget> getTargets() { |
| 168 | + return this.targets; |
| 169 | + } |
| 170 | + |
| 171 | + /** |
| 172 | + * {@inheritDoc} |
| 173 | + */ |
| 174 | + @Generated |
| 175 | + @Override |
| 176 | + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { |
| 177 | + jsonWriter.writeStartObject(); |
| 178 | + jsonWriter.writeStringField("text", this.text); |
| 179 | + jsonWriter.writeArrayField("targets", this.targets, (writer, element) -> writer.writeJson(element)); |
| 180 | + jsonWriter.writeStringField("script", this.script); |
| 181 | + jsonWriter.writeStringField("language", this.language); |
| 182 | + jsonWriter.writeStringField("textType", this.textType == null ? null : this.textType.toString()); |
| 183 | + return jsonWriter.writeEndObject(); |
| 184 | + } |
| 185 | + |
| 186 | + /** |
| 187 | + * Reads an instance of TranslateBodyDetails from the JsonReader. |
| 188 | + * |
| 189 | + * @param jsonReader The JsonReader being read. |
| 190 | + * @return An instance of TranslateBodyDetails if the JsonReader was pointing to an instance of it, or null if it |
| 191 | + * was pointing to JSON null. |
| 192 | + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. |
| 193 | + * @throws IOException If an error occurs while reading the TranslateBodyDetails. |
| 194 | + */ |
| 195 | + @Generated |
| 196 | + public static TranslateBodyDetails fromJson(JsonReader jsonReader) throws IOException { |
| 197 | + return jsonReader.readObject(reader -> { |
| 198 | + String text = null; |
| 199 | + List<TranslateTarget> targets = null; |
| 200 | + String script = null; |
| 201 | + String language = null; |
| 202 | + TextType textType = null; |
| 203 | + while (reader.nextToken() != JsonToken.END_OBJECT) { |
| 204 | + String fieldName = reader.getFieldName(); |
| 205 | + reader.nextToken(); |
| 206 | + |
| 207 | + if ("text".equals(fieldName)) { |
| 208 | + text = reader.getString(); |
| 209 | + } else if ("targets".equals(fieldName)) { |
| 210 | + targets = reader.readArray(reader1 -> TranslateTarget.fromJson(reader1)); |
| 211 | + } else if ("script".equals(fieldName)) { |
| 212 | + script = reader.getString(); |
| 213 | + } else if ("language".equals(fieldName)) { |
| 214 | + language = reader.getString(); |
| 215 | + } else if ("textType".equals(fieldName)) { |
| 216 | + textType = TextType.fromString(reader.getString()); |
| 217 | + } else { |
| 218 | + reader.skipChildren(); |
| 219 | + } |
| 220 | + } |
| 221 | + TranslateBodyDetails deserializedTranslateBodyDetails = new TranslateBodyDetails(text, targets); |
| 222 | + deserializedTranslateBodyDetails.script = script; |
| 223 | + deserializedTranslateBodyDetails.language = language; |
| 224 | + deserializedTranslateBodyDetails.textType = textType; |
| 225 | + |
| 226 | + return deserializedTranslateBodyDetails; |
| 227 | + }); |
| 228 | + } |
| 229 | +} |
0 commit comments