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