Skip to content

Commit f0d931f

Browse files
authored
Remove Jackson usage in Personalizer (#42503)
1 parent b9dd467 commit f0d931f

File tree

67 files changed

+4464
-2314
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+4464
-2314
lines changed

sdk/personalizer/azure-ai-personalizer/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "java",
44
"TagPrefix": "java/personalizer/azure-ai-personalizer",
5-
"Tag": "java/personalizer/azure-ai-personalizer_2583cef92d"
5+
"Tag": "java/personalizer/azure-ai-personalizer_8067625503"
66
}

sdk/personalizer/azure-ai-personalizer/pom.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@
3636
<!-- Configures the Java 9+ run to perform the required module exports, opens, and reads that are necessary for testing but shouldn't be part of the module-info. -->
3737
<javaModulesSurefireArgLine>
3838
--add-exports com.azure.core/com.azure.core.implementation.http=ALL-UNNAMED
39-
--add-exports com.azure.ai.personalizer/com.azure.ai.personalizer.testmodels=com.fasterxml.jackson.databind
4039
--add-opens com.azure.ai.personalizer/com.azure.ai.personalizer=ALL-UNNAMED
41-
--add-opens com.azure.ai.personalizer/com.azure.ai.personalizer.testmodels=com.fasterxml.jackson.databind
4240
--add-opens com.azure.ai.personalizer/com.azure.ai.personalizer.testmodels=com.azure.core
4341
</javaModulesSurefireArgLine>
4442

sdk/personalizer/azure-ai-personalizer/src/main/java/com/azure/ai/personalizer/administration/PersonalizerAdministrationAsyncClient.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -512,23 +512,8 @@ public Mono<Response<BinaryData>> exportModelWithResponse(boolean isSigned) {
512512
* @return the model file generated by Personalizer service.
513513
*/
514514
Mono<Response<BinaryData>> exportModelWithResponse(boolean isSigned, Context context) {
515-
return service.getModels().getWithResponseAsync(isSigned, context).flatMap(streamResponse -> {
516-
return BinaryData.fromFlux(streamResponse.getValue())
517-
.flatMap(binaryData -> {
518-
Response<BinaryData> response = new SimpleResponse<>(
519-
streamResponse.getRequest(),
520-
streamResponse.getStatusCode(),
521-
streamResponse.getHeaders(),
522-
binaryData);
523-
return Mono.just(response);
524-
}).doFinally(ignored -> {
525-
try {
526-
streamResponse.close();
527-
} catch (Exception e) {
528-
logger.logThrowableAsError(e);
529-
}
530-
});
531-
}).onErrorMap(Transforms::mapToHttpResponseExceptionIfExists);
515+
return service.getModels().getWithResponseAsync(isSigned, context)
516+
.onErrorMap(Transforms::mapToHttpResponseExceptionIfExists);
532517
}
533518

534519
/**

sdk/personalizer/azure-ai-personalizer/src/main/java/com/azure/ai/personalizer/administration/models/EvaluationsCreateHeaders.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,32 @@
55
package com.azure.ai.personalizer.administration.models;
66

77
import com.azure.core.annotation.Fluent;
8+
import com.azure.core.http.HttpHeaderName;
89
import com.azure.core.http.HttpHeaders;
9-
import com.fasterxml.jackson.annotation.JsonProperty;
1010

11-
/** The EvaluationsCreateHeaders model. */
11+
/**
12+
* The EvaluationsCreateHeaders model.
13+
*/
1214
@Fluent
1315
public final class EvaluationsCreateHeaders {
1416
/*
1517
* The Location property.
1618
*/
17-
@JsonProperty(value = "Location")
1819
private String location;
1920

2021
// HttpHeaders containing the raw property values.
2122
/**
2223
* Creates an instance of EvaluationsCreateHeaders class.
23-
*
24+
*
2425
* @param rawHeaders The raw HttpHeaders that will be used to create the property values.
2526
*/
2627
public EvaluationsCreateHeaders(HttpHeaders rawHeaders) {
27-
this.location = rawHeaders.getValue("Location");
28+
this.location = rawHeaders.getValue(HttpHeaderName.LOCATION);
2829
}
2930

3031
/**
3132
* Get the location property: The Location property.
32-
*
33+
*
3334
* @return the location value.
3435
*/
3536
public String getLocation() {
@@ -38,7 +39,7 @@ public String getLocation() {
3839

3940
/**
4041
* Set the location property: The Location property.
41-
*
42+
*
4243
* @param location the location value to set.
4344
* @return the EvaluationsCreateHeaders object itself.
4445
*/

sdk/personalizer/azure-ai-personalizer/src/main/java/com/azure/ai/personalizer/administration/models/PersonalizerDateRange.java

Lines changed: 79 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,111 @@
55
package com.azure.ai.personalizer.administration.models;
66

77
import com.azure.core.annotation.Immutable;
8-
import com.fasterxml.jackson.annotation.JsonProperty;
8+
import com.azure.core.util.CoreUtils;
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;
914
import java.time.OffsetDateTime;
1015

11-
/** A date range starting at From and ending at To. */
16+
/**
17+
* A date range starting at From and ending at To.
18+
*/
1219
@Immutable
13-
public class PersonalizerDateRange {
20+
public class PersonalizerDateRange implements JsonSerializable<PersonalizerDateRange> {
1421
/*
1522
* Start date for the range.
1623
*/
17-
@JsonProperty(value = "from", access = JsonProperty.Access.WRITE_ONLY)
1824
private OffsetDateTime from;
1925

2026
/*
2127
* End date for the range.
2228
*/
23-
@JsonProperty(value = "to", access = JsonProperty.Access.WRITE_ONLY)
2429
private OffsetDateTime to;
2530

31+
/**
32+
* Creates an instance of PersonalizerDateRange class.
33+
*/
34+
public PersonalizerDateRange() {
35+
}
36+
2637
/**
2738
* Get the from property: Start date for the range.
28-
*
39+
*
2940
* @return the from value.
3041
*/
3142
public OffsetDateTime getFrom() {
3243
return this.from;
3344
}
3445

46+
/**
47+
* Set the from property: Start date for the range.
48+
*
49+
* @param from the from value to set.
50+
* @return the PersonalizerDateRange object itself.
51+
*/
52+
PersonalizerDateRange setFrom(OffsetDateTime from) {
53+
this.from = from;
54+
return this;
55+
}
56+
3557
/**
3658
* Get the to property: End date for the range.
37-
*
59+
*
3860
* @return the to value.
3961
*/
4062
public OffsetDateTime getTo() {
4163
return this.to;
4264
}
65+
66+
/**
67+
* Set the to property: End date for the range.
68+
*
69+
* @param to the to value to set.
70+
* @return the PersonalizerDateRange object itself.
71+
*/
72+
PersonalizerDateRange setTo(OffsetDateTime to) {
73+
this.to = to;
74+
return this;
75+
}
76+
77+
/**
78+
* {@inheritDoc}
79+
*/
80+
@Override
81+
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
82+
jsonWriter.writeStartObject();
83+
return jsonWriter.writeEndObject();
84+
}
85+
86+
/**
87+
* Reads an instance of PersonalizerDateRange from the JsonReader.
88+
*
89+
* @param jsonReader The JsonReader being read.
90+
* @return An instance of PersonalizerDateRange if the JsonReader was pointing to an instance of it, or null if it
91+
* was pointing to JSON null.
92+
* @throws IOException If an error occurs while reading the PersonalizerDateRange.
93+
*/
94+
public static PersonalizerDateRange fromJson(JsonReader jsonReader) throws IOException {
95+
return jsonReader.readObject(reader -> {
96+
PersonalizerDateRange deserializedPersonalizerDateRange = new PersonalizerDateRange();
97+
while (reader.nextToken() != JsonToken.END_OBJECT) {
98+
String fieldName = reader.getFieldName();
99+
reader.nextToken();
100+
101+
if ("from".equals(fieldName)) {
102+
deserializedPersonalizerDateRange.from = reader
103+
.getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString()));
104+
} else if ("to".equals(fieldName)) {
105+
deserializedPersonalizerDateRange.to = reader
106+
.getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString()));
107+
} else {
108+
reader.skipChildren();
109+
}
110+
}
111+
112+
return deserializedPersonalizerDateRange;
113+
});
114+
}
43115
}

sdk/personalizer/azure-ai-personalizer/src/main/java/com/azure/ai/personalizer/administration/models/PersonalizerEvaluation.java

Lines changed: 86 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,88 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33
// Code generated by Microsoft (R) AutoRest Code Generator.
4-
54
package com.azure.ai.personalizer.administration.models;
65

76
import com.azure.ai.personalizer.models.EvaluationJobStatus;
87
import com.azure.ai.personalizer.models.EvaluationType;
98
import com.azure.core.annotation.Fluent;
10-
import com.fasterxml.jackson.annotation.JsonProperty;
9+
import com.azure.core.util.CoreUtils;
10+
import com.azure.json.JsonReader;
11+
import com.azure.json.JsonSerializable;
12+
import com.azure.json.JsonToken;
13+
import com.azure.json.JsonWriter;
14+
import java.io.IOException;
1115
import java.time.OffsetDateTime;
16+
import java.time.format.DateTimeFormatter;
1217
import java.util.List;
1318

14-
/** A counterfactual evaluation. */
19+
/**
20+
* A counterfactual evaluation.
21+
*/
1522
@Fluent
16-
public final class PersonalizerEvaluation {
23+
public final class PersonalizerEvaluation implements JsonSerializable<PersonalizerEvaluation> {
24+
1725
/*
1826
* The ID of the evaluation.
1927
*/
20-
@JsonProperty(value = "id", access = JsonProperty.Access.WRITE_ONLY)
2128
private String id;
2229

2330
/*
2431
* The name of the evaluation.
2532
*/
26-
@JsonProperty(value = "name", access = JsonProperty.Access.WRITE_ONLY)
2733
private String name;
2834

2935
/*
3036
* The start time of the evaluation.
3137
*/
32-
@JsonProperty(value = "startTime", access = JsonProperty.Access.WRITE_ONLY)
3338
private OffsetDateTime startTime;
3439

3540
/*
3641
* The end time of the evaluation.
3742
*/
38-
@JsonProperty(value = "endTime", access = JsonProperty.Access.WRITE_ONLY)
3943
private OffsetDateTime endTime;
4044

4145
/*
4246
* The ID of the job processing the evaluation.
4347
*/
44-
@JsonProperty(value = "jobId", access = JsonProperty.Access.WRITE_ONLY)
4548
private String jobId;
4649

4750
/*
4851
* The status of the job processing the evaluation.
4952
*/
50-
@JsonProperty(value = "status", access = JsonProperty.Access.WRITE_ONLY)
5153
private EvaluationJobStatus status;
5254

5355
/*
5456
* The results of the evaluation.
5557
*/
56-
@JsonProperty(value = "policyResults")
5758
private List<PersonalizerPolicyResult> policyResults;
5859

5960
/*
6061
* Feature Importance.
6162
*/
62-
@JsonProperty(value = "featureImportance")
6363
private List<List<String>> featureImportance;
6464

6565
/*
6666
* Evaluation type (manual or through Automatic Optimization).
6767
*/
68-
@JsonProperty(value = "evaluationType")
6968
private EvaluationType evaluationType;
7069

7170
/*
7271
* Thr optimal policy.
7372
*/
74-
@JsonProperty(value = "optimalPolicy")
7573
private String optimalPolicy;
7674

7775
/*
7876
* Creation time.
7977
*/
80-
@JsonProperty(value = "creationTime")
8178
private OffsetDateTime creationTime;
8279

80+
/**
81+
* Creates an instance of PersonalizerEvaluation class.
82+
*/
83+
public PersonalizerEvaluation() {
84+
}
85+
8386
/**
8487
* Get the id property: The ID of the evaluation.
8588
*
@@ -233,4 +236,72 @@ PersonalizerEvaluation setCreationTime(OffsetDateTime creationTime) {
233236
this.creationTime = creationTime;
234237
return this;
235238
}
239+
240+
/**
241+
* {@inheritDoc}
242+
*/
243+
@Override
244+
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
245+
jsonWriter.writeStartObject();
246+
jsonWriter.writeArrayField("policyResults", this.policyResults, (writer, element) -> writer.writeJson(element));
247+
jsonWriter.writeArrayField("featureImportance", this.featureImportance,
248+
(writer, element) -> writer.writeArray(element, (writer1, element1) -> writer1.writeString(element1)));
249+
jsonWriter.writeStringField("evaluationType",
250+
this.evaluationType == null ? null : this.evaluationType.toString());
251+
jsonWriter.writeStringField("optimalPolicy", this.optimalPolicy);
252+
jsonWriter.writeStringField("creationTime",
253+
this.creationTime == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.creationTime));
254+
return jsonWriter.writeEndObject();
255+
}
256+
257+
/**
258+
* Reads an instance of PersonalizerEvaluation from the JsonReader.
259+
*
260+
* @param jsonReader The JsonReader being read.
261+
* @return An instance of PersonalizerEvaluation if the JsonReader was pointing to an instance of it, or null if it
262+
* was pointing to JSON null.
263+
* @throws IOException If an error occurs while reading the PersonalizerEvaluation.
264+
*/
265+
public static PersonalizerEvaluation fromJson(JsonReader jsonReader) throws IOException {
266+
return jsonReader.readObject(reader -> {
267+
PersonalizerEvaluation deserializedPersonalizerEvaluation = new PersonalizerEvaluation();
268+
while (reader.nextToken() != JsonToken.END_OBJECT) {
269+
String fieldName = reader.getFieldName();
270+
reader.nextToken();
271+
if ("id".equals(fieldName)) {
272+
deserializedPersonalizerEvaluation.id = reader.getString();
273+
} else if ("name".equals(fieldName)) {
274+
deserializedPersonalizerEvaluation.name = reader.getString();
275+
} else if ("startTime".equals(fieldName)) {
276+
deserializedPersonalizerEvaluation.startTime = reader
277+
.getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString()));
278+
} else if ("endTime".equals(fieldName)) {
279+
deserializedPersonalizerEvaluation.endTime = reader
280+
.getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString()));
281+
} else if ("jobId".equals(fieldName)) {
282+
deserializedPersonalizerEvaluation.jobId = reader.getString();
283+
} else if ("status".equals(fieldName)) {
284+
deserializedPersonalizerEvaluation.status = EvaluationJobStatus.fromString(reader.getString());
285+
} else if ("policyResults".equals(fieldName)) {
286+
List<PersonalizerPolicyResult> policyResults
287+
= reader.readArray(reader1 -> PersonalizerPolicyResult.fromJson(reader1));
288+
deserializedPersonalizerEvaluation.policyResults = policyResults;
289+
} else if ("featureImportance".equals(fieldName)) {
290+
List<List<String>> featureImportance
291+
= reader.readArray(reader1 -> reader1.readArray(reader2 -> reader2.getString()));
292+
deserializedPersonalizerEvaluation.featureImportance = featureImportance;
293+
} else if ("evaluationType".equals(fieldName)) {
294+
deserializedPersonalizerEvaluation.evaluationType = EvaluationType.fromString(reader.getString());
295+
} else if ("optimalPolicy".equals(fieldName)) {
296+
deserializedPersonalizerEvaluation.optimalPolicy = reader.getString();
297+
} else if ("creationTime".equals(fieldName)) {
298+
deserializedPersonalizerEvaluation.creationTime = reader
299+
.getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString()));
300+
} else {
301+
reader.skipChildren();
302+
}
303+
}
304+
return deserializedPersonalizerEvaluation;
305+
});
306+
}
236307
}

0 commit comments

Comments
 (0)