Skip to content

Commit

Permalink
[Face] Use Stream-Style Serialization in Face SDK (#41073)
Browse files Browse the repository at this point in the history
  • Loading branch information
mssfang authored Jul 18, 2024
1 parent e828ea7 commit 57ae552
Show file tree
Hide file tree
Showing 56 changed files with 2,097 additions and 456 deletions.
5 changes: 5 additions & 0 deletions sdk/face/azure-ai-vision-face/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
<artifactId>azure-core-http-netty</artifactId>
<version>1.15.2</version> <!-- {x-version-update;com.azure:azure-core-http-netty;dependency} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-json</artifactId>
<version>1.1.0</version> <!-- {x-version-update;com.azure:azure-json;dependency} -->
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@

import com.azure.core.annotation.Generated;
import com.azure.core.annotation.Immutable;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;

/**
* The DetectFromUrlImplRequest model.
*/
@Immutable
public final class DetectFromUrlImplRequest {
public final class DetectFromUrlImplRequest implements JsonSerializable<DetectFromUrlImplRequest> {

/*
* URL of input image.
*/
@Generated
@JsonProperty(value = "url")
private final String url;

/**
Expand All @@ -27,8 +29,7 @@ public final class DetectFromUrlImplRequest {
* @param url the url value to set.
*/
@Generated
@JsonCreator
public DetectFromUrlImplRequest(@JsonProperty(value = "url") String url) {
public DetectFromUrlImplRequest(String url) {
this.url = url;
}

Expand All @@ -41,4 +42,41 @@ public DetectFromUrlImplRequest(@JsonProperty(value = "url") String url) {
public String getUrl() {
return this.url;
}

/**
* {@inheritDoc}
*/
@Generated
@Override
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
jsonWriter.writeStringField("url", this.url);
return jsonWriter.writeEndObject();
}

/**
* Reads an instance of DetectFromUrlImplRequest from the JsonReader.
*
* @param jsonReader The JsonReader being read.
* @return An instance of DetectFromUrlImplRequest if the JsonReader was pointing to an instance of it, or null if
* it was pointing to JSON null.
* @throws IllegalStateException If the deserialized JSON object was missing any required properties.
* @throws IOException If an error occurs while reading the DetectFromUrlImplRequest.
*/
@Generated
public static DetectFromUrlImplRequest fromJson(JsonReader jsonReader) throws IOException {
return jsonReader.readObject(reader -> {
String url = null;
while (reader.nextToken() != JsonToken.END_OBJECT) {
String fieldName = reader.getFieldName();
reader.nextToken();
if ("url".equals(fieldName)) {
url = reader.getString();
} else {
reader.skipChildren();
}
}
return new DetectFromUrlImplRequest(url);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,43 @@
import com.azure.ai.vision.face.models.FindSimilarMatchMode;
import com.azure.core.annotation.Fluent;
import com.azure.core.annotation.Generated;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;
import java.util.List;

/**
* The FindSimilarRequest model.
*/
@Fluent
public final class FindSimilarRequest {
public final class FindSimilarRequest implements JsonSerializable<FindSimilarRequest> {

/*
* faceId of the query face. User needs to call "Detect" first to get a valid faceId. Note that this faceId is not
* persisted and will expire 24 hours after the detection call.
*/
@Generated
@JsonProperty(value = "faceId")
private final String faceId;

/*
* The number of top similar faces returned. The valid range is [1, 1000]. Default value is 20.
*/
@Generated
@JsonProperty(value = "maxNumOfCandidatesReturned")
private Integer maxNumOfCandidatesReturned;

/*
* Similar face searching mode. It can be 'matchPerson' or 'matchFace'. Default value is 'matchPerson'.
*/
@Generated
@JsonProperty(value = "mode")
private FindSimilarMatchMode mode;

/*
* An array of candidate faceIds. All of them are created by "Detect" and the faceIds will expire 24 hours after the
* detection call. The number of faceIds is limited to 1000.
*/
@Generated
@JsonProperty(value = "faceIds")
private final List<String> faceIds;

/**
Expand All @@ -53,9 +52,7 @@ public final class FindSimilarRequest {
* @param faceIds the faceIds value to set.
*/
@Generated
@JsonCreator
public FindSimilarRequest(@JsonProperty(value = "faceId") String faceId,
@JsonProperty(value = "faceIds") List<String> faceIds) {
public FindSimilarRequest(String faceId, List<String> faceIds) {
this.faceId = faceId;
this.faceIds = faceIds;
}
Expand Down Expand Up @@ -129,4 +126,56 @@ public FindSimilarRequest setMode(FindSimilarMatchMode mode) {
public List<String> getFaceIds() {
return this.faceIds;
}

/**
* {@inheritDoc}
*/
@Generated
@Override
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
jsonWriter.writeStringField("faceId", this.faceId);
jsonWriter.writeArrayField("faceIds", this.faceIds, (writer, element) -> writer.writeString(element));
jsonWriter.writeNumberField("maxNumOfCandidatesReturned", this.maxNumOfCandidatesReturned);
jsonWriter.writeStringField("mode", this.mode == null ? null : this.mode.toString());
return jsonWriter.writeEndObject();
}

/**
* Reads an instance of FindSimilarRequest from the JsonReader.
*
* @param jsonReader The JsonReader being read.
* @return An instance of FindSimilarRequest if the JsonReader was pointing to an instance of it, or null if it was
* pointing to JSON null.
* @throws IllegalStateException If the deserialized JSON object was missing any required properties.
* @throws IOException If an error occurs while reading the FindSimilarRequest.
*/
@Generated
public static FindSimilarRequest fromJson(JsonReader jsonReader) throws IOException {
return jsonReader.readObject(reader -> {
String faceId = null;
List<String> faceIds = null;
Integer maxNumOfCandidatesReturned = null;
FindSimilarMatchMode mode = null;
while (reader.nextToken() != JsonToken.END_OBJECT) {
String fieldName = reader.getFieldName();
reader.nextToken();
if ("faceId".equals(fieldName)) {
faceId = reader.getString();
} else if ("faceIds".equals(fieldName)) {
faceIds = reader.readArray(reader1 -> reader1.getString());
} else if ("maxNumOfCandidatesReturned".equals(fieldName)) {
maxNumOfCandidatesReturned = reader.getNullable(JsonReader::getInt);
} else if ("mode".equals(fieldName)) {
mode = FindSimilarMatchMode.fromString(reader.getString());
} else {
reader.skipChildren();
}
}
FindSimilarRequest deserializedFindSimilarRequest = new FindSimilarRequest(faceId, faceIds);
deserializedFindSimilarRequest.maxNumOfCandidatesReturned = maxNumOfCandidatesReturned;
deserializedFindSimilarRequest.mode = mode;
return deserializedFindSimilarRequest;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@

import com.azure.core.annotation.Generated;
import com.azure.core.annotation.Immutable;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;
import java.util.List;

/**
* The GroupRequest model.
*/
@Immutable
public final class GroupRequest {
public final class GroupRequest implements JsonSerializable<GroupRequest> {

/*
* Array of candidate faceIds created by "Detect". The maximum is 1000 faces.
*/
@Generated
@JsonProperty(value = "faceIds")
private final List<String> faceIds;

/**
Expand All @@ -28,8 +30,7 @@ public final class GroupRequest {
* @param faceIds the faceIds value to set.
*/
@Generated
@JsonCreator
public GroupRequest(@JsonProperty(value = "faceIds") List<String> faceIds) {
public GroupRequest(List<String> faceIds) {
this.faceIds = faceIds;
}

Expand All @@ -42,4 +43,41 @@ public GroupRequest(@JsonProperty(value = "faceIds") List<String> faceIds) {
public List<String> getFaceIds() {
return this.faceIds;
}

/**
* {@inheritDoc}
*/
@Generated
@Override
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
jsonWriter.writeArrayField("faceIds", this.faceIds, (writer, element) -> writer.writeString(element));
return jsonWriter.writeEndObject();
}

/**
* Reads an instance of GroupRequest from the JsonReader.
*
* @param jsonReader The JsonReader being read.
* @return An instance of GroupRequest if the JsonReader was pointing to an instance of it, or null if it was
* pointing to JSON null.
* @throws IllegalStateException If the deserialized JSON object was missing any required properties.
* @throws IOException If an error occurs while reading the GroupRequest.
*/
@Generated
public static GroupRequest fromJson(JsonReader jsonReader) throws IOException {
return jsonReader.readObject(reader -> {
List<String> faceIds = null;
while (reader.nextToken() != JsonToken.END_OBJECT) {
String fieldName = reader.getFieldName();
reader.nextToken();
if ("faceIds".equals(fieldName)) {
faceIds = reader.readArray(reader1 -> reader1.getString());
} else {
reader.skipChildren();
}
}
return new GroupRequest(faceIds);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,28 @@

import com.azure.core.annotation.Generated;
import com.azure.core.annotation.Immutable;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;

/**
* The VerifyFaceToFaceRequest model.
*/
@Immutable
public final class VerifyFaceToFaceRequest {
public final class VerifyFaceToFaceRequest implements JsonSerializable<VerifyFaceToFaceRequest> {

/*
* The faceId of one face, come from "Detect".
*/
@Generated
@JsonProperty(value = "faceId1")
private final String faceId1;

/*
* The faceId of another face, come from "Detect".
*/
@Generated
@JsonProperty(value = "faceId2")
private final String faceId2;

/**
Expand All @@ -35,9 +36,7 @@ public final class VerifyFaceToFaceRequest {
* @param faceId2 the faceId2 value to set.
*/
@Generated
@JsonCreator
public VerifyFaceToFaceRequest(@JsonProperty(value = "faceId1") String faceId1,
@JsonProperty(value = "faceId2") String faceId2) {
public VerifyFaceToFaceRequest(String faceId1, String faceId2) {
this.faceId1 = faceId1;
this.faceId2 = faceId2;
}
Expand All @@ -61,4 +60,45 @@ public String getFaceId1() {
public String getFaceId2() {
return this.faceId2;
}

/**
* {@inheritDoc}
*/
@Generated
@Override
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
jsonWriter.writeStringField("faceId1", this.faceId1);
jsonWriter.writeStringField("faceId2", this.faceId2);
return jsonWriter.writeEndObject();
}

/**
* Reads an instance of VerifyFaceToFaceRequest from the JsonReader.
*
* @param jsonReader The JsonReader being read.
* @return An instance of VerifyFaceToFaceRequest if the JsonReader was pointing to an instance of it, or null if it
* was pointing to JSON null.
* @throws IllegalStateException If the deserialized JSON object was missing any required properties.
* @throws IOException If an error occurs while reading the VerifyFaceToFaceRequest.
*/
@Generated
public static VerifyFaceToFaceRequest fromJson(JsonReader jsonReader) throws IOException {
return jsonReader.readObject(reader -> {
String faceId1 = null;
String faceId2 = null;
while (reader.nextToken() != JsonToken.END_OBJECT) {
String fieldName = reader.getFieldName();
reader.nextToken();
if ("faceId1".equals(fieldName)) {
faceId1 = reader.getString();
} else if ("faceId2".equals(fieldName)) {
faceId2 = reader.getString();
} else {
reader.skipChildren();
}
}
return new VerifyFaceToFaceRequest(faceId1, faceId2);
});
}
}
Loading

0 comments on commit 57ae552

Please sign in to comment.