Skip to content

Commit 44f65d4

Browse files
authored
Migrate azure-ai-translation-document to azure-json (#42504)
Migrate azure-ai-translation-document to azure-json
1 parent ae4f12e commit 44f65d4

30 files changed

+1041
-148
lines changed

.vscode/cspell.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,17 @@
13011301
"upserted",
13021302
"raud"
13031303
]
1304+
},
1305+
{
1306+
"filename": "sdk/translation/azure-ai-translation-document/**",
1307+
"words": [
1308+
"cancelacurrentlyprocessingorqueuedtranslation",
1309+
"returnsalistofbatchrequestssubmittedandthestatusforeachrequest",
1310+
"returnsalistofsupporteddocumentformats",
1311+
"returnsthestatusofasingledocumentinabatchtranslationrequest",
1312+
"submitadocumenttranslationrequesttothedocumenttranslationservice",
1313+
"translateasingledocument"
1314+
]
13041315
}
13051316
],
13061317
"allowCompoundWords": true

sdk/translation/azure-ai-translation-document/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ Code generated by Microsoft (R) TypeSpec Code Generator.
4747
</properties>
4848

4949
<dependencies>
50+
<dependency>
51+
<groupId>com.azure</groupId>
52+
<artifactId>azure-json</artifactId>
53+
<version>1.3.0</version> <!-- {x-version-update;com.azure:azure-json;dependency} -->
54+
</dependency>
5055
<dependency>
5156
<groupId>com.azure</groupId>
5257
<artifactId>azure-core</artifactId>

sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/models/BatchRequest.java

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,35 @@
55

66
import com.azure.core.annotation.Fluent;
77
import com.azure.core.annotation.Generated;
8-
import com.fasterxml.jackson.annotation.JsonCreator;
9-
import com.fasterxml.jackson.annotation.JsonProperty;
8+
import com.azure.json.JsonReader;
9+
import com.azure.json.JsonSerializable;
10+
import com.azure.json.JsonToken;
11+
import com.azure.json.JsonWriter;
12+
import java.io.IOException;
1013
import java.util.List;
1114

1215
/**
1316
* Definition for the input batch translation request.
1417
*/
1518
@Fluent
16-
public final class BatchRequest {
19+
public final class BatchRequest implements JsonSerializable<BatchRequest> {
1720

1821
/*
1922
* Source of the input documents
2023
*/
2124
@Generated
22-
@JsonProperty(value = "source")
2325
private final SourceInput source;
2426

2527
/*
2628
* Location of the destination for the output
2729
*/
2830
@Generated
29-
@JsonProperty(value = "targets")
3031
private final List<TargetInput> targets;
3132

3233
/*
3334
* Storage type of the input documents source string
3435
*/
3536
@Generated
36-
@JsonProperty(value = "storageType")
3737
private StorageInputType storageType;
3838

3939
/**
@@ -43,9 +43,7 @@ public final class BatchRequest {
4343
* @param targets the targets value to set.
4444
*/
4545
@Generated
46-
@JsonCreator
47-
public BatchRequest(@JsonProperty(value = "source") SourceInput source,
48-
@JsonProperty(value = "targets") List<TargetInput> targets) {
46+
public BatchRequest(SourceInput source, List<TargetInput> targets) {
4947
this.source = source;
5048
this.targets = targets;
5149
}
@@ -91,4 +89,51 @@ public BatchRequest setStorageType(StorageInputType storageType) {
9189
this.storageType = storageType;
9290
return this;
9391
}
92+
93+
/**
94+
* {@inheritDoc}
95+
*/
96+
@Generated
97+
@Override
98+
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
99+
jsonWriter.writeStartObject();
100+
jsonWriter.writeJsonField("source", this.source);
101+
jsonWriter.writeArrayField("targets", this.targets, (writer, element) -> writer.writeJson(element));
102+
jsonWriter.writeStringField("storageType", this.storageType == null ? null : this.storageType.toString());
103+
return jsonWriter.writeEndObject();
104+
}
105+
106+
/**
107+
* Reads an instance of BatchRequest from the JsonReader.
108+
*
109+
* @param jsonReader The JsonReader being read.
110+
* @return An instance of BatchRequest if the JsonReader was pointing to an instance of it, or null if it was
111+
* pointing to JSON null.
112+
* @throws IllegalStateException If the deserialized JSON object was missing any required properties.
113+
* @throws IOException If an error occurs while reading the BatchRequest.
114+
*/
115+
@Generated
116+
public static BatchRequest fromJson(JsonReader jsonReader) throws IOException {
117+
return jsonReader.readObject(reader -> {
118+
SourceInput source = null;
119+
List<TargetInput> targets = null;
120+
StorageInputType storageType = null;
121+
while (reader.nextToken() != JsonToken.END_OBJECT) {
122+
String fieldName = reader.getFieldName();
123+
reader.nextToken();
124+
if ("source".equals(fieldName)) {
125+
source = SourceInput.fromJson(reader);
126+
} else if ("targets".equals(fieldName)) {
127+
targets = reader.readArray(reader1 -> TargetInput.fromJson(reader1));
128+
} else if ("storageType".equals(fieldName)) {
129+
storageType = StorageInputType.fromString(reader.getString());
130+
} else {
131+
reader.skipChildren();
132+
}
133+
}
134+
BatchRequest deserializedBatchRequest = new BatchRequest(source, targets);
135+
deserializedBatchRequest.storageType = storageType;
136+
return deserializedBatchRequest;
137+
});
138+
}
94139
}

sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/models/DocumentFilter.java

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55

66
import com.azure.core.annotation.Fluent;
77
import com.azure.core.annotation.Generated;
8-
import com.fasterxml.jackson.annotation.JsonProperty;
8+
import com.azure.json.JsonReader;
9+
import com.azure.json.JsonSerializable;
10+
import com.azure.json.JsonToken;
11+
import com.azure.json.JsonWriter;
12+
import java.io.IOException;
913

1014
/**
1115
* Document filter.
1216
*/
1317
@Fluent
14-
public final class DocumentFilter {
18+
public final class DocumentFilter implements JsonSerializable<DocumentFilter> {
1519

1620
/*
1721
* A case-sensitive prefix string to filter documents in the source path for
@@ -20,7 +24,6 @@ public final class DocumentFilter {
2024
* to restrict sub folders for translation.
2125
*/
2226
@Generated
23-
@JsonProperty(value = "prefix")
2427
private String prefix;
2528

2629
/*
@@ -29,7 +32,6 @@ public final class DocumentFilter {
2932
* This is most often use for file extensions
3033
*/
3134
@Generated
32-
@JsonProperty(value = "suffix")
3335
private String suffix;
3436

3537
/**
@@ -92,4 +94,43 @@ public DocumentFilter setSuffix(String suffix) {
9294
this.suffix = suffix;
9395
return this;
9496
}
97+
98+
/**
99+
* {@inheritDoc}
100+
*/
101+
@Generated
102+
@Override
103+
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
104+
jsonWriter.writeStartObject();
105+
jsonWriter.writeStringField("prefix", this.prefix);
106+
jsonWriter.writeStringField("suffix", this.suffix);
107+
return jsonWriter.writeEndObject();
108+
}
109+
110+
/**
111+
* Reads an instance of DocumentFilter from the JsonReader.
112+
*
113+
* @param jsonReader The JsonReader being read.
114+
* @return An instance of DocumentFilter if the JsonReader was pointing to an instance of it, or null if it was
115+
* pointing to JSON null.
116+
* @throws IOException If an error occurs while reading the DocumentFilter.
117+
*/
118+
@Generated
119+
public static DocumentFilter fromJson(JsonReader jsonReader) throws IOException {
120+
return jsonReader.readObject(reader -> {
121+
DocumentFilter deserializedDocumentFilter = new DocumentFilter();
122+
while (reader.nextToken() != JsonToken.END_OBJECT) {
123+
String fieldName = reader.getFieldName();
124+
reader.nextToken();
125+
if ("prefix".equals(fieldName)) {
126+
deserializedDocumentFilter.prefix = reader.getString();
127+
} else if ("suffix".equals(fieldName)) {
128+
deserializedDocumentFilter.suffix = reader.getString();
129+
} else {
130+
reader.skipChildren();
131+
}
132+
}
133+
return deserializedDocumentFilter;
134+
});
135+
}
95136
}

0 commit comments

Comments
 (0)