Skip to content

Commit d00525e

Browse files
authored
Migrate to stream style serialization - Azure communication Identity (Azure#40967)
1 parent f606805 commit d00525e

19 files changed

+695
-311
lines changed

eng/code-quality-reports/src/main/resources/revapi/revapi.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,14 @@
582582
"code": "java.missing.oldSuperType",
583583
"old": "class com.azure.resourcemanager.network.models.FirewallPacketCaptureParameters",
584584
"justification": "service bug fix."
585+
},
586+
{
587+
"ignore": true,
588+
"code": "java.annotation.removed",
589+
"old": "method com.azure.communication.identity.models.CommunicationTokenScope com.azure.communication.identity.models.CommunicationTokenScope::fromString(java.lang.String)",
590+
"new": "method com.azure.communication.identity.models.CommunicationTokenScope com.azure.communication.identity.models.CommunicationTokenScope::fromString(java.lang.String)",
591+
"annotation": "@com.fasterxml.jackson.annotation.JsonCreator",
592+
"justification": "Migration to azure-json"
585593
}
586594
]
587595
}

sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/CommunicationIdentitiesImpl.java

Lines changed: 137 additions & 169 deletions
Large diffs are not rendered by default.

sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/CommunicationIdentityClientImpl.java

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,68 +6,79 @@
66

77
import com.azure.core.http.HttpPipeline;
88
import com.azure.core.http.HttpPipelineBuilder;
9-
import com.azure.core.http.policy.CookiePolicy;
109
import com.azure.core.http.policy.RetryPolicy;
1110
import com.azure.core.http.policy.UserAgentPolicy;
1211
import com.azure.core.util.serializer.JacksonAdapter;
1312
import com.azure.core.util.serializer.SerializerAdapter;
1413

15-
/** Initializes a new instance of the CommunicationIdentityClient type. */
14+
/**
15+
* Initializes a new instance of the CommunicationIdentityClient type.
16+
*/
1617
public final class CommunicationIdentityClientImpl {
17-
/** The communication resource, for example https://my-resource.communication.azure.com. */
18+
/**
19+
* The communication resource, for example https://my-resource.communication.azure.com.
20+
*/
1821
private final String endpoint;
1922

2023
/**
2124
* Gets The communication resource, for example https://my-resource.communication.azure.com.
22-
*
25+
*
2326
* @return the endpoint value.
2427
*/
2528
public String getEndpoint() {
2629
return this.endpoint;
2730
}
2831

29-
/** Api Version. */
32+
/**
33+
* Api Version.
34+
*/
3035
private final String apiVersion;
3136

3237
/**
3338
* Gets Api Version.
34-
*
39+
*
3540
* @return the apiVersion value.
3641
*/
3742
public String getApiVersion() {
3843
return this.apiVersion;
3944
}
4045

41-
/** The HTTP pipeline to send requests through. */
46+
/**
47+
* The HTTP pipeline to send requests through.
48+
*/
4249
private final HttpPipeline httpPipeline;
4350

4451
/**
4552
* Gets The HTTP pipeline to send requests through.
46-
*
53+
*
4754
* @return the httpPipeline value.
4855
*/
4956
public HttpPipeline getHttpPipeline() {
5057
return this.httpPipeline;
5158
}
5259

53-
/** The serializer to serialize an object into a string. */
60+
/**
61+
* The serializer to serialize an object into a string.
62+
*/
5463
private final SerializerAdapter serializerAdapter;
5564

5665
/**
5766
* Gets The serializer to serialize an object into a string.
58-
*
67+
*
5968
* @return the serializerAdapter value.
6069
*/
6170
public SerializerAdapter getSerializerAdapter() {
6271
return this.serializerAdapter;
6372
}
6473

65-
/** The CommunicationIdentitiesImpl object to access its operations. */
74+
/**
75+
* The CommunicationIdentitiesImpl object to access its operations.
76+
*/
6677
private final CommunicationIdentitiesImpl communicationIdentities;
6778

6879
/**
6980
* Gets the CommunicationIdentitiesImpl object to access its operations.
70-
*
81+
*
7182
* @return the CommunicationIdentitiesImpl object.
7283
*/
7384
public CommunicationIdentitiesImpl getCommunicationIdentities() {
@@ -76,23 +87,18 @@ public CommunicationIdentitiesImpl getCommunicationIdentities() {
7687

7788
/**
7889
* Initializes an instance of CommunicationIdentityClient client.
79-
*
90+
*
8091
* @param endpoint The communication resource, for example https://my-resource.communication.azure.com.
8192
* @param apiVersion Api Version.
8293
*/
8394
public CommunicationIdentityClientImpl(String endpoint, String apiVersion) {
84-
this(
85-
new HttpPipelineBuilder()
86-
.policies(new UserAgentPolicy(), new RetryPolicy(), new CookiePolicy())
87-
.build(),
88-
JacksonAdapter.createDefaultSerializerAdapter(),
89-
endpoint,
90-
apiVersion);
95+
this(new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy()).build(),
96+
JacksonAdapter.createDefaultSerializerAdapter(), endpoint, apiVersion);
9197
}
9298

9399
/**
94100
* Initializes an instance of CommunicationIdentityClient client.
95-
*
101+
*
96102
* @param httpPipeline The HTTP pipeline to send requests through.
97103
* @param endpoint The communication resource, for example https://my-resource.communication.azure.com.
98104
* @param apiVersion Api Version.
@@ -103,14 +109,14 @@ public CommunicationIdentityClientImpl(HttpPipeline httpPipeline, String endpoin
103109

104110
/**
105111
* Initializes an instance of CommunicationIdentityClient client.
106-
*
112+
*
107113
* @param httpPipeline The HTTP pipeline to send requests through.
108114
* @param serializerAdapter The serializer to serialize an object into a string.
109115
* @param endpoint The communication resource, for example https://my-resource.communication.azure.com.
110116
* @param apiVersion Api Version.
111117
*/
112-
public CommunicationIdentityClientImpl(
113-
HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, String endpoint, String apiVersion) {
118+
public CommunicationIdentityClientImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter,
119+
String endpoint, String apiVersion) {
114120
this.httpPipeline = httpPipeline;
115121
this.serializerAdapter = serializerAdapter;
116122
this.endpoint = endpoint;

sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/CommunicationError.java

Lines changed: 66 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,52 @@
55
package com.azure.communication.identity.implementation.models;
66

77
import com.azure.core.annotation.Fluent;
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
import java.util.List;
1014

11-
/** The Communication Services error. */
15+
/**
16+
* The Communication Services error.
17+
*/
1218
@Fluent
13-
public final class CommunicationError {
19+
public final class CommunicationError implements JsonSerializable<CommunicationError> {
1420
/*
1521
* The error code.
1622
*/
17-
@JsonProperty(value = "code", required = true)
1823
private String code;
1924

2025
/*
2126
* The error message.
2227
*/
23-
@JsonProperty(value = "message", required = true)
2428
private String message;
2529

2630
/*
2731
* The error target.
2832
*/
29-
@JsonProperty(value = "target", access = JsonProperty.Access.WRITE_ONLY)
3033
private String target;
3134

3235
/*
3336
* Further details about specific errors that led to this error.
3437
*/
35-
@JsonProperty(value = "details", access = JsonProperty.Access.WRITE_ONLY)
3638
private List<CommunicationError> details;
3739

3840
/*
3941
* The inner error if any.
4042
*/
41-
@JsonProperty(value = "innererror", access = JsonProperty.Access.WRITE_ONLY)
4243
private CommunicationError innerError;
4344

44-
/** Creates an instance of CommunicationError class. */
45-
public CommunicationError() {}
45+
/**
46+
* Creates an instance of CommunicationError class.
47+
*/
48+
public CommunicationError() {
49+
}
4650

4751
/**
4852
* Get the code property: The error code.
49-
*
53+
*
5054
* @return the code value.
5155
*/
5256
public String getCode() {
@@ -55,7 +59,7 @@ public String getCode() {
5559

5660
/**
5761
* Set the code property: The error code.
58-
*
62+
*
5963
* @param code the code value to set.
6064
* @return the CommunicationError object itself.
6165
*/
@@ -66,7 +70,7 @@ public CommunicationError setCode(String code) {
6670

6771
/**
6872
* Get the message property: The error message.
69-
*
73+
*
7074
* @return the message value.
7175
*/
7276
public String getMessage() {
@@ -75,7 +79,7 @@ public String getMessage() {
7579

7680
/**
7781
* Set the message property: The error message.
78-
*
82+
*
7983
* @param message the message value to set.
8084
* @return the CommunicationError object itself.
8185
*/
@@ -86,7 +90,7 @@ public CommunicationError setMessage(String message) {
8690

8791
/**
8892
* Get the target property: The error target.
89-
*
93+
*
9094
* @return the target value.
9195
*/
9296
public String getTarget() {
@@ -95,7 +99,7 @@ public String getTarget() {
9599

96100
/**
97101
* Get the details property: Further details about specific errors that led to this error.
98-
*
102+
*
99103
* @return the details value.
100104
*/
101105
public List<CommunicationError> getDetails() {
@@ -104,10 +108,55 @@ public List<CommunicationError> getDetails() {
104108

105109
/**
106110
* Get the innerError property: The inner error if any.
107-
*
111+
*
108112
* @return the innerError value.
109113
*/
110114
public CommunicationError getInnerError() {
111115
return this.innerError;
112116
}
117+
118+
@Override
119+
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
120+
jsonWriter.writeStartObject();
121+
jsonWriter.writeStringField("code", this.code);
122+
jsonWriter.writeStringField("message", this.message);
123+
return jsonWriter.writeEndObject();
124+
}
125+
126+
/**
127+
* Reads an instance of CommunicationError from the JsonReader.
128+
*
129+
* @param jsonReader The JsonReader being read.
130+
* @return An instance of CommunicationError if the JsonReader was pointing to an instance of it, or null if it was
131+
* pointing to JSON null.
132+
* @throws IllegalStateException If the deserialized JSON object was missing any required properties.
133+
* @throws IOException If an error occurs while reading the CommunicationError.
134+
*/
135+
public static CommunicationError fromJson(JsonReader jsonReader) throws IOException {
136+
return jsonReader.readObject(reader -> {
137+
CommunicationError deserializedCommunicationError = new CommunicationError();
138+
while (reader.nextToken() != JsonToken.END_OBJECT) {
139+
String fieldName = reader.getFieldName();
140+
reader.nextToken();
141+
142+
if ("code".equals(fieldName)) {
143+
deserializedCommunicationError.code = reader.getString();
144+
} else if ("message".equals(fieldName)) {
145+
deserializedCommunicationError.message = reader.getString();
146+
} else if ("target".equals(fieldName)) {
147+
deserializedCommunicationError.target = reader.getString();
148+
} else if ("details".equals(fieldName)) {
149+
List<CommunicationError> details
150+
= reader.readArray(reader1 -> CommunicationError.fromJson(reader1));
151+
deserializedCommunicationError.details = details;
152+
} else if ("innererror".equals(fieldName)) {
153+
deserializedCommunicationError.innerError = CommunicationError.fromJson(reader);
154+
} else {
155+
reader.skipChildren();
156+
}
157+
}
158+
159+
return deserializedCommunicationError;
160+
});
161+
}
113162
}

0 commit comments

Comments
 (0)