diff --git a/eng/code-quality-reports/src/main/resources/revapi/revapi.json b/eng/code-quality-reports/src/main/resources/revapi/revapi.json index 1f45584be3b7..c97bacacd98f 100644 --- a/eng/code-quality-reports/src/main/resources/revapi/revapi.json +++ b/eng/code-quality-reports/src/main/resources/revapi/revapi.json @@ -492,6 +492,13 @@ "old" : ".*? com\\.azure\\.communication\\.callautomation\\.models.*", "new" : ".*? com\\.azure\\.communication\\.callautomation\\.models.*", "justification": "Migration to azure-json" + }, + { + "regex": true, + "code" : "java\\.annotation\\.removed", + "old" : ".*? com\\.azure\\.communication\\.chat\\.models.*", + "new" : ".*? com\\.azure\\.communication\\.chat\\.models.*", + "justification": "Migration to azure-json" } ] } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/ChatAsyncClient.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/ChatAsyncClient.java index e3866bd5b11b..e2b3f213a48e 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/ChatAsyncClient.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/ChatAsyncClient.java @@ -167,7 +167,7 @@ Mono> createChatThread(CreateChatThreadOptions context = context == null ? Context.NONE : context; try { return this.chatClient.createChatThreadWithResponseAsync( - CreateChatThreadOptionsConverter.convert(options), options.getIdempotencyToken(), context) + CreateChatThreadOptionsConverter.convert(options), context) .onErrorMap(CommunicationErrorResponseException.class, e -> translateException(e)) .map(result -> new SimpleResponse( result, CreateChatThreadResultConverter.convert(result.getValue()))); diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/AzureCommunicationChatServiceImplBuilder.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/AzureCommunicationChatServiceImplBuilder.java index abed72eb84d0..4d29bb960ea7 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/AzureCommunicationChatServiceImplBuilder.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/AzureCommunicationChatServiceImplBuilder.java @@ -6,11 +6,12 @@ import com.azure.core.annotation.Generated; import com.azure.core.annotation.ServiceClientBuilder; +import com.azure.core.client.traits.AzureKeyCredentialTrait; import com.azure.core.client.traits.ConfigurationTrait; import com.azure.core.client.traits.EndpointTrait; import com.azure.core.client.traits.HttpTrait; +import com.azure.core.credential.AzureKeyCredential; import com.azure.core.http.HttpClient; -import com.azure.core.http.HttpHeaderName; import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpPipeline; import com.azure.core.http.HttpPipelineBuilder; @@ -18,8 +19,9 @@ import com.azure.core.http.policy.AddDatePolicy; import com.azure.core.http.policy.AddHeadersFromContextPolicy; import com.azure.core.http.policy.AddHeadersPolicy; -import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.http.policy.AzureKeyCredentialPolicy; import com.azure.core.http.policy.HttpLoggingPolicy; +import com.azure.core.http.policy.HttpLogOptions; import com.azure.core.http.policy.HttpPipelinePolicy; import com.azure.core.http.policy.HttpPolicyProviders; import com.azure.core.http.policy.RequestIdPolicy; @@ -44,6 +46,7 @@ @ServiceClientBuilder(serviceClients = { AzureCommunicationChatServiceImpl.class }) public final class AzureCommunicationChatServiceImplBuilder implements HttpTrait, ConfigurationTrait, + AzureKeyCredentialTrait, EndpointTrait { @Generated private static final String SDK_NAME = "name"; @@ -172,6 +175,22 @@ public AzureCommunicationChatServiceImplBuilder configuration(Configuration conf return this; } + /* + * The AzureKeyCredential used for authentication. + */ + @Generated + private AzureKeyCredential azureKeyCredential; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public AzureCommunicationChatServiceImplBuilder credential(AzureKeyCredential azureKeyCredential) { + this.azureKeyCredential = azureKeyCredential; + return this; + } + /* * The service endpoint */ @@ -249,6 +268,7 @@ public AzureCommunicationChatServiceImplBuilder retryPolicy(RetryPolicy retryPol */ @Generated public AzureCommunicationChatServiceImpl buildClient() { + this.validateClient(); HttpPipeline localPipeline = (pipeline != null) ? pipeline : createHttpPipeline(); String localApiVersion = (apiVersion != null) ? apiVersion : "2024-03-07"; SerializerAdapter localSerializerAdapter @@ -258,6 +278,13 @@ public AzureCommunicationChatServiceImpl buildClient() { return client; } + @Generated + private void validateClient() { + // This method is invoked from 'buildInnerClient'/'buildClient' method. + // Developer can customize this method, to validate that the necessary conditions are met for the new client. + Objects.requireNonNull(endpoint, "'endpoint' cannot be null."); + } + @Generated private HttpPipeline createHttpPipeline() { Configuration buildConfiguration @@ -271,23 +298,28 @@ private HttpPipeline createHttpPipeline() { policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion, buildConfiguration)); policies.add(new RequestIdPolicy()); policies.add(new AddHeadersFromContextPolicy()); - HttpHeaders headers = new HttpHeaders(); - localClientOptions.getHeaders() - .forEach(header -> headers.set(HttpHeaderName.fromString(header.getName()), header.getValue())); - if (headers.getSize() > 0) { + HttpHeaders headers = CoreUtils.createHttpHeadersFromClientOptions(localClientOptions); + if (headers != null) { policies.add(new AddHeadersPolicy(headers)); } - this.pipelinePolicies.stream().filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) .forEach(p -> policies.add(p)); HttpPolicyProviders.addBeforeRetryPolicies(policies); policies.add(ClientBuilderUtil.validateAndGetRetryPolicy(retryPolicy, retryOptions, new RetryPolicy())); policies.add(new AddDatePolicy()); - this.pipelinePolicies.stream().filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) + if (azureKeyCredential != null) { + policies.add(new AzureKeyCredentialPolicy("Authorization", azureKeyCredential)); + } + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) .forEach(p -> policies.add(p)); HttpPolicyProviders.addAfterRetryPolicies(policies); - policies.add(new HttpLoggingPolicy(httpLogOptions)); + policies.add(new HttpLoggingPolicy(localHttpLogOptions)); HttpPipeline httpPipeline = new HttpPipelineBuilder().policies(policies.toArray(new HttpPipelinePolicy[0])) - .httpClient(httpClient).clientOptions(localClientOptions).build(); + .httpClient(httpClient) + .clientOptions(localClientOptions) + .build(); return httpPipeline; } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/ChatThreadsImpl.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/ChatThreadsImpl.java index 46e9fbf4d5c6..30039164d9d5 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/ChatThreadsImpl.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/ChatThreadsImpl.java @@ -2063,9 +2063,7 @@ public void sendTypingNotification(String chatThreadId) { /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. * @throws CommunicationErrorResponseException thrown if the request is rejected by server on status code 401, 403, @@ -2087,9 +2085,7 @@ public Mono> listChatReadReceiptsNextSingl /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. @@ -2111,9 +2107,7 @@ public Mono> listChatReadReceiptsNextSingl /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. * @throws CommunicationErrorResponseException thrown if the request is rejected by server on status code 401, 403, @@ -2129,9 +2123,7 @@ public PagedResponse listChatReadReceiptsNextSinglePage( /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. @@ -2148,9 +2140,7 @@ public PagedResponse listChatReadReceiptsNextSinglePage( /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. * @throws CommunicationErrorResponseException thrown if the request is rejected by server on status code 401, 403, @@ -2171,9 +2161,7 @@ public Mono> listChatMessagesNextSinglePageAsync(Stri /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. @@ -2194,9 +2182,7 @@ public Mono> listChatMessagesNextSinglePageAsync(Stri /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. * @throws CommunicationErrorResponseException thrown if the request is rejected by server on status code 401, 403, @@ -2212,9 +2198,7 @@ public PagedResponse listChatMessagesNextSinglePage(String nextLink /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. @@ -2231,9 +2215,7 @@ public PagedResponse listChatMessagesNextSinglePage(String nextLink /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. * @throws CommunicationErrorResponseException thrown if the request is rejected by server on status code 401, 403, @@ -2255,9 +2237,7 @@ public Mono> listChatParticipantsNextSinglePageAs /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. @@ -2279,9 +2259,7 @@ public Mono> listChatParticipantsNextSinglePageAs /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. * @throws CommunicationErrorResponseException thrown if the request is rejected by server on status code 401, 403, @@ -2297,9 +2275,7 @@ public PagedResponse listChatParticipantsNextSinglePage(String /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/ChatsImpl.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/ChatsImpl.java index 5a70e42baa2c..dea89e8d8093 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/ChatsImpl.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/ChatsImpl.java @@ -30,6 +30,7 @@ import com.azure.core.http.rest.Response; import com.azure.core.http.rest.RestProxy; import com.azure.core.util.Context; +import com.azure.core.util.CoreUtils; import com.azure.core.util.FluxUtil; import java.time.OffsetDateTime; import reactor.core.publisher.Mono; @@ -59,8 +60,8 @@ public final class ChatsImpl { } /** - * The interface defining all the services for AzureCommunicationChatServiceChats to be used by the proxy service - * to perform REST calls. + * The interface defining all the services for AzureCommunicationChatServiceChats to be used by the proxy service to + * perform REST calls. */ @Host("{endpoint}") @ServiceInterface(name = "AzureCommunicationCh") @@ -72,10 +73,10 @@ public interface ChatsService { code = { 401, 403, 429, 503 }) @UnexpectedResponseExceptionType(CommunicationErrorResponseException.class) Mono> createChatThread(@HostParam("endpoint") String endpoint, - @HeaderParam("repeatability-request-id") String repeatabilityRequestId, @QueryParam("api-version") String apiVersion, @BodyParam("application/json") CreateChatThreadOptions createChatThreadRequest, - @HeaderParam("Accept") String accept, Context context); + @HeaderParam("Accept") String accept, + @HeaderParam("repeatability-request-id") String repeatabilityRequestId, Context context); @Get("/chat/threads") @ExpectedResponses({ 200 }) @@ -112,11 +113,6 @@ Mono> listChatThreadsNext( * Creates a chat thread. * * @param createChatThreadRequest Request payload for creating a chat thread. - * @param repeatabilityRequestId If specified, the client directs that the request is repeatable; that is, that the - * client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate - * response without the server executing the request multiple times. The value of the Repeatability-Request-Id is an - * opaque string representing a client-generated, globally unique for all time, identifier for the request. It is - * recommended to use version 4 (random) UUIDs. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. * @throws CommunicationErrorResponseException thrown if the request is rejected by server on status code 401, 403, @@ -126,22 +122,17 @@ Mono> listChatThreadsNext( * {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> createChatThreadWithResponseAsync( - CreateChatThreadOptions createChatThreadRequest, String repeatabilityRequestId) { + public Mono> + createChatThreadWithResponseAsync(CreateChatThreadOptions createChatThreadRequest) { final String accept = "application/json"; return FluxUtil.withContext(context -> service.createChatThread(this.client.getEndpoint(), - repeatabilityRequestId, this.client.getApiVersion(), createChatThreadRequest, accept, context)); + this.client.getApiVersion(), createChatThreadRequest, accept, CoreUtils.randomUuid().toString(), context)); } /** * Creates a chat thread. * * @param createChatThreadRequest Request payload for creating a chat thread. - * @param repeatabilityRequestId If specified, the client directs that the request is repeatable; that is, that the - * client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate - * response without the server executing the request multiple times. The value of the Repeatability-Request-Id is an - * opaque string representing a client-generated, globally unique for all time, identifier for the request. It is - * recommended to use version 4 (random) UUIDs. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. @@ -152,34 +143,11 @@ public Mono> createChatThreadWithResponseAsync( * {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> createChatThreadWithResponseAsync( - CreateChatThreadOptions createChatThreadRequest, String repeatabilityRequestId, Context context) { + public Mono> + createChatThreadWithResponseAsync(CreateChatThreadOptions createChatThreadRequest, Context context) { final String accept = "application/json"; - return service.createChatThread(this.client.getEndpoint(), repeatabilityRequestId, this.client.getApiVersion(), - createChatThreadRequest, accept, context); - } - - /** - * Creates a chat thread. - * - * @param createChatThreadRequest Request payload for creating a chat thread. - * @param repeatabilityRequestId If specified, the client directs that the request is repeatable; that is, that the - * client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate - * response without the server executing the request multiple times. The value of the Repeatability-Request-Id is an - * opaque string representing a client-generated, globally unique for all time, identifier for the request. It is - * recommended to use version 4 (random) UUIDs. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server on status code 401, 403, - * 429, 503. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return result of the create chat thread operation on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono createChatThreadAsync(CreateChatThreadOptions createChatThreadRequest, - String repeatabilityRequestId) { - return createChatThreadWithResponseAsync(createChatThreadRequest, repeatabilityRequestId) - .flatMap(res -> Mono.justOrEmpty(res.getValue())); + return service.createChatThread(this.client.getEndpoint(), this.client.getApiVersion(), createChatThreadRequest, + accept, CoreUtils.randomUuid().toString(), context); } /** @@ -195,8 +163,7 @@ public Mono createChatThreadAsync(CreateChatThreadOption */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono createChatThreadAsync(CreateChatThreadOptions createChatThreadRequest) { - final String repeatabilityRequestId = null; - return createChatThreadWithResponseAsync(createChatThreadRequest, repeatabilityRequestId) + return createChatThreadWithResponseAsync(createChatThreadRequest) .flatMap(res -> Mono.justOrEmpty(res.getValue())); } @@ -204,11 +171,6 @@ public Mono createChatThreadAsync(CreateChatThreadOption * Creates a chat thread. * * @param createChatThreadRequest Request payload for creating a chat thread. - * @param repeatabilityRequestId If specified, the client directs that the request is repeatable; that is, that the - * client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate - * response without the server executing the request multiple times. The value of the Repeatability-Request-Id is an - * opaque string representing a client-generated, globally unique for all time, identifier for the request. It is - * recommended to use version 4 (random) UUIDs. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. @@ -219,8 +181,8 @@ public Mono createChatThreadAsync(CreateChatThreadOption */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono createChatThreadAsync(CreateChatThreadOptions createChatThreadRequest, - String repeatabilityRequestId, Context context) { - return createChatThreadWithResponseAsync(createChatThreadRequest, repeatabilityRequestId, context) + Context context) { + return createChatThreadWithResponseAsync(createChatThreadRequest, context) .flatMap(res -> Mono.justOrEmpty(res.getValue())); } @@ -228,11 +190,6 @@ public Mono createChatThreadAsync(CreateChatThreadOption * Creates a chat thread. * * @param createChatThreadRequest Request payload for creating a chat thread. - * @param repeatabilityRequestId If specified, the client directs that the request is repeatable; that is, that the - * client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate - * response without the server executing the request multiple times. The value of the Repeatability-Request-Id is an - * opaque string representing a client-generated, globally unique for all time, identifier for the request. It is - * recommended to use version 4 (random) UUIDs. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. @@ -242,31 +199,9 @@ public Mono createChatThreadAsync(CreateChatThreadOption * @return result of the create chat thread operation along with {@link Response}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response createChatThreadWithResponse( - CreateChatThreadOptions createChatThreadRequest, String repeatabilityRequestId, Context context) { - return createChatThreadWithResponseAsync(createChatThreadRequest, repeatabilityRequestId, context).block(); - } - - /** - * Creates a chat thread. - * - * @param createChatThreadRequest Request payload for creating a chat thread. - * @param repeatabilityRequestId If specified, the client directs that the request is repeatable; that is, that the - * client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate - * response without the server executing the request multiple times. The value of the Repeatability-Request-Id is an - * opaque string representing a client-generated, globally unique for all time, identifier for the request. It is - * recommended to use version 4 (random) UUIDs. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server on status code 401, 403, - * 429, 503. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return result of the create chat thread operation. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public CreateChatThreadResult createChatThread(CreateChatThreadOptions createChatThreadRequest, - String repeatabilityRequestId) { - return createChatThreadWithResponse(createChatThreadRequest, repeatabilityRequestId, Context.NONE).getValue(); + public Response + createChatThreadWithResponse(CreateChatThreadOptions createChatThreadRequest, Context context) { + return createChatThreadWithResponseAsync(createChatThreadRequest, context).block(); } /** @@ -282,8 +217,7 @@ public CreateChatThreadResult createChatThread(CreateChatThreadOptions createCha */ @ServiceMethod(returns = ReturnType.SINGLE) public CreateChatThreadResult createChatThread(CreateChatThreadOptions createChatThreadRequest) { - final String repeatabilityRequestId = null; - return createChatThreadWithResponse(createChatThreadRequest, repeatabilityRequestId, Context.NONE).getValue(); + return createChatThreadWithResponse(createChatThreadRequest, Context.NONE).getValue(); } /** @@ -591,9 +525,7 @@ public void deleteChatThread(String chatThreadId) { /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. * @throws CommunicationErrorResponseException thrown if the request is rejected by server on status code 401, 403, @@ -613,9 +545,7 @@ public Mono> listChatThreadsNextSinglePageAsync(St /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. @@ -635,9 +565,7 @@ public Mono> listChatThreadsNextSinglePageAsync(St /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. * @throws CommunicationErrorResponseException thrown if the request is rejected by server on status code 401, 403, @@ -653,9 +581,7 @@ public PagedResponse listChatThreadsNextSinglePage(String nextLi /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/AddChatParticipantsOptions.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/AddChatParticipantsOptions.java index cd1037a86632..1f0000208599 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/AddChatParticipantsOptions.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/AddChatParticipantsOptions.java @@ -5,18 +5,21 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -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; /** * Participants to be added to the thread. */ @Fluent -public final class AddChatParticipantsOptions { +public final class AddChatParticipantsOptions implements JsonSerializable { /* * Participants to add to a chat thread. */ - @JsonProperty(value = "participants", required = true) private List participants; /** @@ -44,4 +47,42 @@ public AddChatParticipantsOptions setParticipants(List particip this.participants = participants; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeArrayField("participants", this.participants, (writer, element) -> writer.writeJson(element)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of AddChatParticipantsOptions from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of AddChatParticipantsOptions 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 AddChatParticipantsOptions. + */ + public static AddChatParticipantsOptions fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + AddChatParticipantsOptions deserializedAddChatParticipantsOptions = new AddChatParticipantsOptions(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("participants".equals(fieldName)) { + List participants = reader.readArray(reader1 -> ChatParticipant.fromJson(reader1)); + deserializedAddChatParticipantsOptions.participants = participants; + } else { + reader.skipChildren(); + } + } + + return deserializedAddChatParticipantsOptions; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/AddChatParticipantsResult.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/AddChatParticipantsResult.java index 760b63e132b5..fe4e966e0135 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/AddChatParticipantsResult.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/AddChatParticipantsResult.java @@ -5,18 +5,21 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Immutable; -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; /** * Result of the add chat participants operation. */ @Immutable -public final class AddChatParticipantsResult { +public final class AddChatParticipantsResult implements JsonSerializable { /* * The participants that failed to be added to the chat thread. */ - @JsonProperty(value = "invalidParticipants", access = JsonProperty.Access.WRITE_ONLY) private List invalidParticipants; /** @@ -33,4 +36,41 @@ public AddChatParticipantsResult() { public List getInvalidParticipants() { return this.invalidParticipants; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of AddChatParticipantsResult from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of AddChatParticipantsResult if the JsonReader was pointing to an instance of it, or null if + * it was pointing to JSON null. + * @throws IOException If an error occurs while reading the AddChatParticipantsResult. + */ + public static AddChatParticipantsResult fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + AddChatParticipantsResult deserializedAddChatParticipantsResult = new AddChatParticipantsResult(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("invalidParticipants".equals(fieldName)) { + List invalidParticipants + = reader.readArray(reader1 -> CommunicationError.fromJson(reader1)); + deserializedAddChatParticipantsResult.invalidParticipants = invalidParticipants; + } else { + reader.skipChildren(); + } + } + + return deserializedAddChatParticipantsResult; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatAttachment.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatAttachment.java index bccb27edd8c0..7d1215fb5d1f 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatAttachment.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatAttachment.java @@ -5,41 +5,40 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -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; /** * An attachment in a chat message. */ @Fluent -public final class ChatAttachment { +public final class ChatAttachment implements JsonSerializable { /* * Id of the attachment */ - @JsonProperty(value = "id", required = true) private String id; /* * The type of attachment. */ - @JsonProperty(value = "attachmentType", required = true) private ChatAttachmentType attachmentType; /* * The name of the attachment content. */ - @JsonProperty(value = "name") private String name; /* * The URL where the attachment can be downloaded */ - @JsonProperty(value = "url") private String url; /* * The URL where the preview of attachment can be downloaded */ - @JsonProperty(value = "previewUrl") private String previewUrl; /** @@ -147,4 +146,54 @@ public ChatAttachment setPreviewUrl(String previewUrl) { this.previewUrl = previewUrl; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("id", this.id); + jsonWriter.writeStringField("attachmentType", + this.attachmentType == null ? null : this.attachmentType.toString()); + jsonWriter.writeStringField("name", this.name); + jsonWriter.writeStringField("url", this.url); + jsonWriter.writeStringField("previewUrl", this.previewUrl); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatAttachment from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatAttachment 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 ChatAttachment. + */ + public static ChatAttachment fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ChatAttachment deserializedChatAttachment = new ChatAttachment(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("id".equals(fieldName)) { + deserializedChatAttachment.id = reader.getString(); + } else if ("attachmentType".equals(fieldName)) { + deserializedChatAttachment.attachmentType = ChatAttachmentType.fromString(reader.getString()); + } else if ("name".equals(fieldName)) { + deserializedChatAttachment.name = reader.getString(); + } else if ("url".equals(fieldName)) { + deserializedChatAttachment.url = reader.getString(); + } else if ("previewUrl".equals(fieldName)) { + deserializedChatAttachment.previewUrl = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedChatAttachment; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatAttachmentType.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatAttachmentType.java index 1c6a344e8271..2c39b51b1b26 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatAttachmentType.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatAttachmentType.java @@ -5,7 +5,6 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.util.ExpandableStringEnum; -import com.fasterxml.jackson.annotation.JsonCreator; import java.util.Collection; /** @@ -37,7 +36,6 @@ public ChatAttachmentType() { * @param name a name to look for. * @return the corresponding ChatAttachmentType. */ - @JsonCreator public static ChatAttachmentType fromString(String name) { return fromString(name, ChatAttachmentType.class); } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessage.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessage.java index 06e480dde532..214fb8cc7294 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessage.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessage.java @@ -6,57 +6,56 @@ import com.azure.communication.chat.models.ChatMessageType; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.azure.core.util.CoreUtils; +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.time.OffsetDateTime; +import java.time.format.DateTimeFormatter; import java.util.Map; /** * Chat message. */ @Fluent -public final class ChatMessage { +public final class ChatMessage implements JsonSerializable { /* * The id of the chat message. This id is server generated. */ - @JsonProperty(value = "id", required = true) private String id; /* * The chat message type. */ - @JsonProperty(value = "type", required = true) private ChatMessageType type; /* * Sequence of the chat message in the conversation. */ - @JsonProperty(value = "sequenceId", required = true) private String sequenceId; /* * Version of the chat message. */ - @JsonProperty(value = "version", required = true) private String version; /* * Content of a chat message. */ - @JsonProperty(value = "content") private ChatMessageContent content; /* * The display name of the chat message sender. This property is used to populate sender name for push * notifications. */ - @JsonProperty(value = "senderDisplayName") private String senderDisplayName; /* * The timestamp when the chat message arrived at the server. The timestamp is in RFC3339 format: * `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "createdOn", required = true) private OffsetDateTime createdOn; /* @@ -64,27 +63,23 @@ public final class ChatMessage { * Azure communication user. This model is polymorphic: Apart from kind and rawId, at most one further property may * be set which must match the kind enum value. */ - @JsonProperty(value = "senderCommunicationIdentifier") private CommunicationIdentifierModel senderCommunicationIdentifier; /* * The timestamp (if applicable) when the message was deleted. The timestamp is in RFC3339 format: * `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "deletedOn") private OffsetDateTime deletedOn; /* * The last timestamp (if applicable) when the message was edited. The timestamp is in RFC3339 format: * `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "editedOn") private OffsetDateTime editedOn; /* * Message metadata. */ - @JsonProperty(value = "metadata") private Map metadata; /** @@ -239,8 +234,8 @@ public ChatMessage setCreatedOn(OffsetDateTime createdOn) { /** * Get the senderCommunicationIdentifier property: Identifies a participant in Azure Communication services. A - * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart - * from kind and rawId, at most one further property may be set which must match the kind enum value. + * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from + * kind and rawId, at most one further property may be set which must match the kind enum value. * * @return the senderCommunicationIdentifier value. */ @@ -250,8 +245,8 @@ public CommunicationIdentifierModel getSenderCommunicationIdentifier() { /** * Set the senderCommunicationIdentifier property: Identifies a participant in Azure Communication services. A - * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart - * from kind and rawId, at most one further property may be set which must match the kind enum value. + * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from + * kind and rawId, at most one further property may be set which must match the kind enum value. * * @param senderCommunicationIdentifier the senderCommunicationIdentifier value to set. * @return the ChatMessage object itself. @@ -324,4 +319,79 @@ public ChatMessage setMetadata(Map metadata) { this.metadata = metadata; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("id", this.id); + jsonWriter.writeStringField("type", this.type == null ? null : this.type.toString()); + jsonWriter.writeStringField("sequenceId", this.sequenceId); + jsonWriter.writeStringField("version", this.version); + jsonWriter.writeStringField("createdOn", + this.createdOn == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.createdOn)); + jsonWriter.writeJsonField("content", this.content); + jsonWriter.writeStringField("senderDisplayName", this.senderDisplayName); + jsonWriter.writeJsonField("senderCommunicationIdentifier", this.senderCommunicationIdentifier); + jsonWriter.writeStringField("deletedOn", + this.deletedOn == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.deletedOn)); + jsonWriter.writeStringField("editedOn", + this.editedOn == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.editedOn)); + jsonWriter.writeMapField("metadata", this.metadata, (writer, element) -> writer.writeString(element)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatMessage from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatMessage 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 ChatMessage. + */ + public static ChatMessage fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ChatMessage deserializedChatMessage = new ChatMessage(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("id".equals(fieldName)) { + deserializedChatMessage.id = reader.getString(); + } else if ("type".equals(fieldName)) { + deserializedChatMessage.type = ChatMessageType.fromString(reader.getString()); + } else if ("sequenceId".equals(fieldName)) { + deserializedChatMessage.sequenceId = reader.getString(); + } else if ("version".equals(fieldName)) { + deserializedChatMessage.version = reader.getString(); + } else if ("createdOn".equals(fieldName)) { + deserializedChatMessage.createdOn = reader + .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString())); + } else if ("content".equals(fieldName)) { + deserializedChatMessage.content = ChatMessageContent.fromJson(reader); + } else if ("senderDisplayName".equals(fieldName)) { + deserializedChatMessage.senderDisplayName = reader.getString(); + } else if ("senderCommunicationIdentifier".equals(fieldName)) { + deserializedChatMessage.senderCommunicationIdentifier + = CommunicationIdentifierModel.fromJson(reader); + } else if ("deletedOn".equals(fieldName)) { + deserializedChatMessage.deletedOn = reader + .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString())); + } else if ("editedOn".equals(fieldName)) { + deserializedChatMessage.editedOn = reader + .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString())); + } else if ("metadata".equals(fieldName)) { + Map metadata = reader.readMap(reader1 -> reader1.getString()); + deserializedChatMessage.metadata = metadata; + } else { + reader.skipChildren(); + } + } + + return deserializedChatMessage; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageContent.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageContent.java index 0ce005db9fc4..90fab2fa68ab 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageContent.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageContent.java @@ -5,36 +5,36 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -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; /** * Content of a chat message. */ @Fluent -public final class ChatMessageContent { +public final class ChatMessageContent implements JsonSerializable { /* * Chat message content for messages of types text or html. */ - @JsonProperty(value = "message") private String message; /* * Chat message content for messages of type topicUpdated. */ - @JsonProperty(value = "topic") private String topic; /* * Chat message content for messages of types participantAdded or participantRemoved. */ - @JsonProperty(value = "participants") private List participants; /* * List of attachments for this message */ - @JsonProperty(value = "attachments") private List attachments; /* @@ -42,7 +42,6 @@ public final class ChatMessageContent { * Azure communication user. This model is polymorphic: Apart from kind and rawId, at most one further property may * be set which must match the kind enum value. */ - @JsonProperty(value = "initiatorCommunicationIdentifier") private CommunicationIdentifierModel initiatorCommunicationIdentifier; /** @@ -92,8 +91,7 @@ public ChatMessageContent setTopic(String topic) { } /** - * Get the participants property: Chat message content for messages of types participantAdded or - * participantRemoved. + * Get the participants property: Chat message content for messages of types participantAdded or participantRemoved. * * @return the participants value. */ @@ -102,8 +100,7 @@ public List getParticipants() { } /** - * Set the participants property: Chat message content for messages of types participantAdded or - * participantRemoved. + * Set the participants property: Chat message content for messages of types participantAdded or participantRemoved. * * @param participants the participants value to set. * @return the ChatMessageContent object itself. @@ -135,8 +132,8 @@ public ChatMessageContent setAttachments(List attachments) { /** * Get the initiatorCommunicationIdentifier property: Identifies a participant in Azure Communication services. A - * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart - * from kind and rawId, at most one further property may be set which must match the kind enum value. + * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from + * kind and rawId, at most one further property may be set which must match the kind enum value. * * @return the initiatorCommunicationIdentifier value. */ @@ -146,8 +143,8 @@ public CommunicationIdentifierModel getInitiatorCommunicationIdentifier() { /** * Set the initiatorCommunicationIdentifier property: Identifies a participant in Azure Communication services. A - * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart - * from kind and rawId, at most one further property may be set which must match the kind enum value. + * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from + * kind and rawId, at most one further property may be set which must match the kind enum value. * * @param initiatorCommunicationIdentifier the initiatorCommunicationIdentifier value to set. * @return the ChatMessageContent object itself. @@ -157,4 +154,55 @@ public CommunicationIdentifierModel getInitiatorCommunicationIdentifier() { this.initiatorCommunicationIdentifier = initiatorCommunicationIdentifier; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("message", this.message); + jsonWriter.writeStringField("topic", this.topic); + jsonWriter.writeArrayField("participants", this.participants, (writer, element) -> writer.writeJson(element)); + jsonWriter.writeArrayField("attachments", this.attachments, (writer, element) -> writer.writeJson(element)); + jsonWriter.writeJsonField("initiatorCommunicationIdentifier", this.initiatorCommunicationIdentifier); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatMessageContent from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatMessageContent if the JsonReader was pointing to an instance of it, or null if it was + * pointing to JSON null. + * @throws IOException If an error occurs while reading the ChatMessageContent. + */ + public static ChatMessageContent fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ChatMessageContent deserializedChatMessageContent = new ChatMessageContent(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("message".equals(fieldName)) { + deserializedChatMessageContent.message = reader.getString(); + } else if ("topic".equals(fieldName)) { + deserializedChatMessageContent.topic = reader.getString(); + } else if ("participants".equals(fieldName)) { + List participants = reader.readArray(reader1 -> ChatParticipant.fromJson(reader1)); + deserializedChatMessageContent.participants = participants; + } else if ("attachments".equals(fieldName)) { + List attachments = reader.readArray(reader1 -> ChatAttachment.fromJson(reader1)); + deserializedChatMessageContent.attachments = attachments; + } else if ("initiatorCommunicationIdentifier".equals(fieldName)) { + deserializedChatMessageContent.initiatorCommunicationIdentifier + = CommunicationIdentifierModel.fromJson(reader); + } else { + reader.skipChildren(); + } + } + + return deserializedChatMessageContent; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageReadReceipt.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageReadReceipt.java index a2ee436fe6f3..f32af20a9ce9 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageReadReceipt.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageReadReceipt.java @@ -5,32 +5,35 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.azure.core.util.CoreUtils; +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.time.OffsetDateTime; +import java.time.format.DateTimeFormatter; /** * A chat message read receipt indicates the time a chat message was read by a recipient. */ @Fluent -public final class ChatMessageReadReceipt { +public final class ChatMessageReadReceipt implements JsonSerializable { /* * Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an * Azure communication user. This model is polymorphic: Apart from kind and rawId, at most one further property may * be set which must match the kind enum value. */ - @JsonProperty(value = "senderCommunicationIdentifier", required = true) private CommunicationIdentifierModel senderCommunicationIdentifier; /* * Id of the chat message that has been read. This id is generated by the server. */ - @JsonProperty(value = "chatMessageId", required = true) private String chatMessageId; /* * The time at which the message was read. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "readOn", required = true) private OffsetDateTime readOn; /** @@ -41,8 +44,8 @@ public ChatMessageReadReceipt() { /** * Get the senderCommunicationIdentifier property: Identifies a participant in Azure Communication services. A - * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart - * from kind and rawId, at most one further property may be set which must match the kind enum value. + * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from + * kind and rawId, at most one further property may be set which must match the kind enum value. * * @return the senderCommunicationIdentifier value. */ @@ -52,8 +55,8 @@ public CommunicationIdentifierModel getSenderCommunicationIdentifier() { /** * Set the senderCommunicationIdentifier property: Identifies a participant in Azure Communication services. A - * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart - * from kind and rawId, at most one further property may be set which must match the kind enum value. + * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from + * kind and rawId, at most one further property may be set which must match the kind enum value. * * @param senderCommunicationIdentifier the senderCommunicationIdentifier value to set. * @return the ChatMessageReadReceipt object itself. @@ -105,4 +108,50 @@ public ChatMessageReadReceipt setReadOn(OffsetDateTime readOn) { this.readOn = readOn; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeJsonField("senderCommunicationIdentifier", this.senderCommunicationIdentifier); + jsonWriter.writeStringField("chatMessageId", this.chatMessageId); + jsonWriter.writeStringField("readOn", + this.readOn == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.readOn)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatMessageReadReceipt from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatMessageReadReceipt 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 ChatMessageReadReceipt. + */ + public static ChatMessageReadReceipt fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ChatMessageReadReceipt deserializedChatMessageReadReceipt = new ChatMessageReadReceipt(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("senderCommunicationIdentifier".equals(fieldName)) { + deserializedChatMessageReadReceipt.senderCommunicationIdentifier + = CommunicationIdentifierModel.fromJson(reader); + } else if ("chatMessageId".equals(fieldName)) { + deserializedChatMessageReadReceipt.chatMessageId = reader.getString(); + } else if ("readOn".equals(fieldName)) { + deserializedChatMessageReadReceipt.readOn = reader + .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString())); + } else { + reader.skipChildren(); + } + } + + return deserializedChatMessageReadReceipt; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageReadReceiptsCollection.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageReadReceiptsCollection.java index 77452f5f5f01..480439f93ac2 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageReadReceiptsCollection.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageReadReceiptsCollection.java @@ -5,24 +5,26 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -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; /** * A paged collection of chat message read receipts. */ @Fluent -public final class ChatMessageReadReceiptsCollection { +public final class ChatMessageReadReceiptsCollection implements JsonSerializable { /* * Collection of chat message read receipts. */ - @JsonProperty(value = "value", required = true) private List value; /* * If there are more chat message read receipts that can be retrieved, the next link will be populated. */ - @JsonProperty(value = "nextLink", access = JsonProperty.Access.WRITE_ONLY) private String nextLink; /** @@ -52,12 +54,54 @@ public ChatMessageReadReceiptsCollection setValue(List v } /** - * Get the nextLink property: If there are more chat message read receipts that can be retrieved, the next link - * will be populated. + * Get the nextLink property: If there are more chat message read receipts that can be retrieved, the next link will + * be populated. * * @return the nextLink value. */ public String getNextLink() { return this.nextLink; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeArrayField("value", this.value, (writer, element) -> writer.writeJson(element)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatMessageReadReceiptsCollection from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatMessageReadReceiptsCollection 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 ChatMessageReadReceiptsCollection. + */ + public static ChatMessageReadReceiptsCollection fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ChatMessageReadReceiptsCollection deserializedChatMessageReadReceiptsCollection + = new ChatMessageReadReceiptsCollection(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("value".equals(fieldName)) { + List value + = reader.readArray(reader1 -> ChatMessageReadReceipt.fromJson(reader1)); + deserializedChatMessageReadReceiptsCollection.value = value; + } else if ("nextLink".equals(fieldName)) { + deserializedChatMessageReadReceiptsCollection.nextLink = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedChatMessageReadReceiptsCollection; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessagesCollection.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessagesCollection.java index b5457ea8f662..638c90d943c4 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessagesCollection.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessagesCollection.java @@ -5,24 +5,26 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -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; /** * Collection of chat messages for a particular chat thread. */ @Fluent -public final class ChatMessagesCollection { +public final class ChatMessagesCollection implements JsonSerializable { /* * Collection of chat messages. */ - @JsonProperty(value = "value", required = true) private List value; /* * If there are more chat messages that can be retrieved, the next link will be populated. */ - @JsonProperty(value = "nextLink", access = JsonProperty.Access.WRITE_ONLY) private String nextLink; /** @@ -60,4 +62,44 @@ public ChatMessagesCollection setValue(List value) { public String getNextLink() { return this.nextLink; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeArrayField("value", this.value, (writer, element) -> writer.writeJson(element)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatMessagesCollection from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatMessagesCollection 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 ChatMessagesCollection. + */ + public static ChatMessagesCollection fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ChatMessagesCollection deserializedChatMessagesCollection = new ChatMessagesCollection(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("value".equals(fieldName)) { + List value = reader.readArray(reader1 -> ChatMessage.fromJson(reader1)); + deserializedChatMessagesCollection.value = value; + } else if ("nextLink".equals(fieldName)) { + deserializedChatMessagesCollection.nextLink = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedChatMessagesCollection; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatParticipant.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatParticipant.java index 6e82b15fc694..22a2817b2548 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatParticipant.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatParticipant.java @@ -5,33 +5,36 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.azure.core.util.CoreUtils; +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.time.OffsetDateTime; +import java.time.format.DateTimeFormatter; /** * A participant of the chat thread. */ @Fluent -public final class ChatParticipant { +public final class ChatParticipant implements JsonSerializable { /* * Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an * Azure communication user. This model is polymorphic: Apart from kind and rawId, at most one further property may * be set which must match the kind enum value. */ - @JsonProperty(value = "communicationIdentifier", required = true) private CommunicationIdentifierModel communicationIdentifier; /* * Display name for the chat participant. */ - @JsonProperty(value = "displayName") private String displayName; /* * Time from which the chat history is shared with the participant. The timestamp is in RFC3339 format: * `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "shareHistoryTime") private OffsetDateTime shareHistoryTime; /** @@ -41,9 +44,9 @@ public ChatParticipant() { } /** - * Get the communicationIdentifier property: Identifies a participant in Azure Communication services. A - * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart - * from kind and rawId, at most one further property may be set which must match the kind enum value. + * Get the communicationIdentifier property: Identifies a participant in Azure Communication services. A participant + * is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from kind and + * rawId, at most one further property may be set which must match the kind enum value. * * @return the communicationIdentifier value. */ @@ -52,9 +55,9 @@ public CommunicationIdentifierModel getCommunicationIdentifier() { } /** - * Set the communicationIdentifier property: Identifies a participant in Azure Communication services. A - * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart - * from kind and rawId, at most one further property may be set which must match the kind enum value. + * Set the communicationIdentifier property: Identifies a participant in Azure Communication services. A participant + * is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from kind and + * rawId, at most one further property may be set which must match the kind enum value. * * @param communicationIdentifier the communicationIdentifier value to set. * @return the ChatParticipant object itself. @@ -85,8 +88,8 @@ public ChatParticipant setDisplayName(String displayName) { } /** - * Get the shareHistoryTime property: Time from which the chat history is shared with the participant. The - * timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. + * Get the shareHistoryTime property: Time from which the chat history is shared with the participant. The timestamp + * is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. * * @return the shareHistoryTime value. */ @@ -95,8 +98,8 @@ public OffsetDateTime getShareHistoryTime() { } /** - * Set the shareHistoryTime property: Time from which the chat history is shared with the participant. The - * timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. + * Set the shareHistoryTime property: Time from which the chat history is shared with the participant. The timestamp + * is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. * * @param shareHistoryTime the shareHistoryTime value to set. * @return the ChatParticipant object itself. @@ -105,4 +108,51 @@ public ChatParticipant setShareHistoryTime(OffsetDateTime shareHistoryTime) { this.shareHistoryTime = shareHistoryTime; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeJsonField("communicationIdentifier", this.communicationIdentifier); + jsonWriter.writeStringField("displayName", this.displayName); + jsonWriter.writeStringField("shareHistoryTime", + this.shareHistoryTime == null + ? null + : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.shareHistoryTime)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatParticipant from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatParticipant 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 ChatParticipant. + */ + public static ChatParticipant fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ChatParticipant deserializedChatParticipant = new ChatParticipant(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("communicationIdentifier".equals(fieldName)) { + deserializedChatParticipant.communicationIdentifier = CommunicationIdentifierModel.fromJson(reader); + } else if ("displayName".equals(fieldName)) { + deserializedChatParticipant.displayName = reader.getString(); + } else if ("shareHistoryTime".equals(fieldName)) { + deserializedChatParticipant.shareHistoryTime = reader + .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString())); + } else { + reader.skipChildren(); + } + } + + return deserializedChatParticipant; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatParticipantsCollection.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatParticipantsCollection.java index 8492d8955f1b..a5519d829f56 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatParticipantsCollection.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatParticipantsCollection.java @@ -5,24 +5,26 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -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; /** * Collection of participants belong to a particular thread. */ @Fluent -public final class ChatParticipantsCollection { +public final class ChatParticipantsCollection implements JsonSerializable { /* * Chat participants. */ - @JsonProperty(value = "value", required = true) private List value; /* * If there are more chat participants that can be retrieved, the next link will be populated. */ - @JsonProperty(value = "nextLink", access = JsonProperty.Access.WRITE_ONLY) private String nextLink; /** @@ -60,4 +62,44 @@ public ChatParticipantsCollection setValue(List value) { public String getNextLink() { return this.nextLink; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeArrayField("value", this.value, (writer, element) -> writer.writeJson(element)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatParticipantsCollection from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatParticipantsCollection 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 ChatParticipantsCollection. + */ + public static ChatParticipantsCollection fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ChatParticipantsCollection deserializedChatParticipantsCollection = new ChatParticipantsCollection(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("value".equals(fieldName)) { + List value = reader.readArray(reader1 -> ChatParticipant.fromJson(reader1)); + deserializedChatParticipantsCollection.value = value; + } else if ("nextLink".equals(fieldName)) { + deserializedChatParticipantsCollection.nextLink = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedChatParticipantsCollection; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatThreadItem.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatThreadItem.java index 65a1ab061d08..f8296684489f 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatThreadItem.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatThreadItem.java @@ -5,38 +5,45 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -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.time.OffsetDateTime; +import java.time.format.DateTimeFormatter; -/** Summary information of a chat thread. */ +/** + * Summary information of a chat thread. + */ @Fluent -public final class ChatThreadItem { +public final class ChatThreadItem implements JsonSerializable { /* * Chat thread id. */ - @JsonProperty(value = "id", required = true) private String id; /* * Chat thread topic. */ - @JsonProperty(value = "topic", required = true) private String topic; /* - * The timestamp when the chat thread was deleted. The timestamp is in - * RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. + * The timestamp when the chat thread was deleted. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "deletedOn") private OffsetDateTime deletedOn; /* - * The timestamp when the last message arrived at the server. The timestamp - * is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. + * The timestamp when the last message arrived at the server. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "lastMessageReceivedOn", access = JsonProperty.Access.WRITE_ONLY) private OffsetDateTime lastMessageReceivedOn; + /** + * Creates an instance of ChatThreadItem class. + */ + public ChatThreadItem() { + } + /** * Get the id property: Chat thread id. * @@ -108,4 +115,52 @@ public ChatThreadItem setDeletedOn(OffsetDateTime deletedOn) { public OffsetDateTime getLastMessageReceivedOn() { return this.lastMessageReceivedOn; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("id", this.id); + jsonWriter.writeStringField("topic", this.topic); + jsonWriter.writeStringField("deletedOn", + this.deletedOn == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.deletedOn)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatThreadItem from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatThreadItem 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 ChatThreadItem. + */ + public static ChatThreadItem fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ChatThreadItem deserializedChatThreadItem = new ChatThreadItem(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("id".equals(fieldName)) { + deserializedChatThreadItem.id = reader.getString(); + } else if ("topic".equals(fieldName)) { + deserializedChatThreadItem.topic = reader.getString(); + } else if ("deletedOn".equals(fieldName)) { + deserializedChatThreadItem.deletedOn + = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); + } else if ("lastMessageReceivedOn".equals(fieldName)) { + deserializedChatThreadItem.lastMessageReceivedOn + = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); + } else { + reader.skipChildren(); + } + } + + return deserializedChatThreadItem; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatThreadProperties.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatThreadProperties.java index c0a5fb37a33e..b095c16c1d9b 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatThreadProperties.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatThreadProperties.java @@ -5,30 +5,33 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.azure.core.util.CoreUtils; +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.time.OffsetDateTime; +import java.time.format.DateTimeFormatter; /** * Chat thread. */ @Fluent -public final class ChatThreadProperties { +public final class ChatThreadProperties implements JsonSerializable { /* * Chat thread id. */ - @JsonProperty(value = "id", required = true) private String id; /* * Chat thread topic. */ - @JsonProperty(value = "topic", required = true) private String topic; /* * The timestamp when the chat thread was created. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "createdOn", required = true) private OffsetDateTime createdOn; /* @@ -36,13 +39,11 @@ public final class ChatThreadProperties { * Azure communication user. This model is polymorphic: Apart from kind and rawId, at most one further property may * be set which must match the kind enum value. */ - @JsonProperty(value = "createdByCommunicationIdentifier", required = true) private CommunicationIdentifierModel createdByCommunicationIdentifier; /* * The timestamp when the chat thread was deleted. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "deletedOn") private OffsetDateTime deletedOn; /** @@ -115,8 +116,8 @@ public ChatThreadProperties setCreatedOn(OffsetDateTime createdOn) { /** * Get the createdByCommunicationIdentifier property: Identifies a participant in Azure Communication services. A - * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart - * from kind and rawId, at most one further property may be set which must match the kind enum value. + * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from + * kind and rawId, at most one further property may be set which must match the kind enum value. * * @return the createdByCommunicationIdentifier value. */ @@ -126,8 +127,8 @@ public CommunicationIdentifierModel getCreatedByCommunicationIdentifier() { /** * Set the createdByCommunicationIdentifier property: Identifies a participant in Azure Communication services. A - * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart - * from kind and rawId, at most one further property may be set which must match the kind enum value. + * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from + * kind and rawId, at most one further property may be set which must match the kind enum value. * * @param createdByCommunicationIdentifier the createdByCommunicationIdentifier value to set. * @return the ChatThreadProperties object itself. @@ -159,4 +160,58 @@ public ChatThreadProperties setDeletedOn(OffsetDateTime deletedOn) { this.deletedOn = deletedOn; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("id", this.id); + jsonWriter.writeStringField("topic", this.topic); + jsonWriter.writeStringField("createdOn", + this.createdOn == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.createdOn)); + jsonWriter.writeJsonField("createdByCommunicationIdentifier", this.createdByCommunicationIdentifier); + jsonWriter.writeStringField("deletedOn", + this.deletedOn == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.deletedOn)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatThreadProperties from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatThreadProperties 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 ChatThreadProperties. + */ + public static ChatThreadProperties fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ChatThreadProperties deserializedChatThreadProperties = new ChatThreadProperties(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("id".equals(fieldName)) { + deserializedChatThreadProperties.id = reader.getString(); + } else if ("topic".equals(fieldName)) { + deserializedChatThreadProperties.topic = reader.getString(); + } else if ("createdOn".equals(fieldName)) { + deserializedChatThreadProperties.createdOn = reader + .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString())); + } else if ("createdByCommunicationIdentifier".equals(fieldName)) { + deserializedChatThreadProperties.createdByCommunicationIdentifier + = CommunicationIdentifierModel.fromJson(reader); + } else if ("deletedOn".equals(fieldName)) { + deserializedChatThreadProperties.deletedOn = reader + .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString())); + } else { + reader.skipChildren(); + } + } + + return deserializedChatThreadProperties; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatThreadsItemCollection.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatThreadsItemCollection.java index 2653a33b7df8..6a48e2caf840 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatThreadsItemCollection.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatThreadsItemCollection.java @@ -6,24 +6,26 @@ import com.azure.communication.chat.models.ChatThreadItem; import com.azure.core.annotation.Fluent; -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; /** * Collection of chat threads. */ @Fluent -public final class ChatThreadsItemCollection { +public final class ChatThreadsItemCollection implements JsonSerializable { /* * Collection of chat threads. */ - @JsonProperty(value = "value", required = true) private List value; /* * If there are more chat threads that can be retrieved, the next link will be populated. */ - @JsonProperty(value = "nextLink", access = JsonProperty.Access.WRITE_ONLY) private String nextLink; /** @@ -53,12 +55,51 @@ public ChatThreadsItemCollection setValue(List value) { } /** - * Get the nextLink property: If there are more chat threads that can be retrieved, the next link will be - * populated. + * Get the nextLink property: If there are more chat threads that can be retrieved, the next link will be populated. * * @return the nextLink value. */ public String getNextLink() { return this.nextLink; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeArrayField("value", this.value, (writer, element) -> writer.writeJson(element)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatThreadsItemCollection from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatThreadsItemCollection 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 ChatThreadsItemCollection. + */ + public static ChatThreadsItemCollection fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ChatThreadsItemCollection deserializedChatThreadsItemCollection = new ChatThreadsItemCollection(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("value".equals(fieldName)) { + List value = reader.readArray(reader1 -> ChatThreadItem.fromJson(reader1)); + deserializedChatThreadsItemCollection.value = value; + } else if ("nextLink".equals(fieldName)) { + deserializedChatThreadsItemCollection.nextLink = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedChatThreadsItemCollection; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationCloudEnvironmentModel.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationCloudEnvironmentModel.java index 59c431ffc8fa..f6219281caf5 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationCloudEnvironmentModel.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationCloudEnvironmentModel.java @@ -5,7 +5,6 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.util.ExpandableStringEnum; -import com.fasterxml.jackson.annotation.JsonCreator; import java.util.Collection; /** @@ -42,7 +41,6 @@ public CommunicationCloudEnvironmentModel() { * @param name a name to look for. * @return the corresponding CommunicationCloudEnvironmentModel. */ - @JsonCreator public static CommunicationCloudEnvironmentModel fromString(String name) { return fromString(name, CommunicationCloudEnvironmentModel.class); } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationError.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationError.java index 18a515ecc36d..17b68e91796f 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationError.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationError.java @@ -5,42 +5,41 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -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 Communication Services error. */ @Fluent -public final class CommunicationError { +public final class CommunicationError implements JsonSerializable { /* * The error code. */ - @JsonProperty(value = "code", required = true) private String code; /* * The error message. */ - @JsonProperty(value = "message", required = true) private String message; /* * The error target. */ - @JsonProperty(value = "target", access = JsonProperty.Access.WRITE_ONLY) private String target; /* * Further details about specific errors that led to this error. */ - @JsonProperty(value = "details", access = JsonProperty.Access.WRITE_ONLY) private List details; /* * The inner error if any. */ - @JsonProperty(value = "innererror", access = JsonProperty.Access.WRITE_ONLY) private CommunicationError innerError; /** @@ -115,4 +114,52 @@ public List getDetails() { public CommunicationError getInnerError() { return this.innerError; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("code", this.code); + jsonWriter.writeStringField("message", this.message); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of CommunicationError from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of CommunicationError 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 CommunicationError. + */ + public static CommunicationError fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + CommunicationError deserializedCommunicationError = new CommunicationError(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("code".equals(fieldName)) { + deserializedCommunicationError.code = reader.getString(); + } else if ("message".equals(fieldName)) { + deserializedCommunicationError.message = reader.getString(); + } else if ("target".equals(fieldName)) { + deserializedCommunicationError.target = reader.getString(); + } else if ("details".equals(fieldName)) { + List details + = reader.readArray(reader1 -> CommunicationError.fromJson(reader1)); + deserializedCommunicationError.details = details; + } else if ("innererror".equals(fieldName)) { + deserializedCommunicationError.innerError = CommunicationError.fromJson(reader); + } else { + reader.skipChildren(); + } + } + + return deserializedCommunicationError; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationErrorResponse.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationErrorResponse.java index ee4f0dfab4e7..f4be067601da 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationErrorResponse.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationErrorResponse.java @@ -5,17 +5,20 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -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 Communication Services error. */ @Fluent -public final class CommunicationErrorResponse { +public final class CommunicationErrorResponse implements JsonSerializable { /* * The Communication Services error. */ - @JsonProperty(value = "error", required = true) private CommunicationError error; /** @@ -43,4 +46,41 @@ public CommunicationErrorResponse setError(CommunicationError error) { this.error = error; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeJsonField("error", this.error); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of CommunicationErrorResponse from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of CommunicationErrorResponse 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 CommunicationErrorResponse. + */ + public static CommunicationErrorResponse fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + CommunicationErrorResponse deserializedCommunicationErrorResponse = new CommunicationErrorResponse(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("error".equals(fieldName)) { + deserializedCommunicationErrorResponse.error = CommunicationError.fromJson(reader); + } else { + reader.skipChildren(); + } + } + + return deserializedCommunicationErrorResponse; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationIdentifierModel.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationIdentifierModel.java index 61b7b4d9ca34..3aec73a3ac4d 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationIdentifierModel.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationIdentifierModel.java @@ -5,7 +5,11 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -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; /** * Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an Azure @@ -13,41 +17,35 @@ * which must match the kind enum value. */ @Fluent -public final class CommunicationIdentifierModel { +public final class CommunicationIdentifierModel implements JsonSerializable { /* * The identifier kind. Only required in responses. */ - @JsonProperty(value = "kind") private CommunicationIdentifierModelKind kind; /* * Raw Id of the identifier. Optional in requests, required in responses. */ - @JsonProperty(value = "rawId") private String rawId; /* * The communication user. */ - @JsonProperty(value = "communicationUser") private CommunicationUserIdentifierModel communicationUser; /* * The phone number. */ - @JsonProperty(value = "phoneNumber") private PhoneNumberIdentifierModel phoneNumber; /* * The Microsoft Teams user. */ - @JsonProperty(value = "microsoftTeamsUser") private MicrosoftTeamsUserIdentifierModel microsoftTeamsUser; /* * The Microsoft Teams application. */ - @JsonProperty(value = "microsoftTeamsApp") private MicrosoftTeamsAppIdentifierModel microsoftTeamsApp; /** @@ -175,4 +173,59 @@ public CommunicationIdentifierModel setMicrosoftTeamsApp(MicrosoftTeamsAppIdenti this.microsoftTeamsApp = microsoftTeamsApp; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("kind", this.kind == null ? null : this.kind.toString()); + jsonWriter.writeStringField("rawId", this.rawId); + jsonWriter.writeJsonField("communicationUser", this.communicationUser); + jsonWriter.writeJsonField("phoneNumber", this.phoneNumber); + jsonWriter.writeJsonField("microsoftTeamsUser", this.microsoftTeamsUser); + jsonWriter.writeJsonField("microsoftTeamsApp", this.microsoftTeamsApp); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of CommunicationIdentifierModel from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of CommunicationIdentifierModel if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the CommunicationIdentifierModel. + */ + public static CommunicationIdentifierModel fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + CommunicationIdentifierModel deserializedCommunicationIdentifierModel = new CommunicationIdentifierModel(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("kind".equals(fieldName)) { + deserializedCommunicationIdentifierModel.kind + = CommunicationIdentifierModelKind.fromString(reader.getString()); + } else if ("rawId".equals(fieldName)) { + deserializedCommunicationIdentifierModel.rawId = reader.getString(); + } else if ("communicationUser".equals(fieldName)) { + deserializedCommunicationIdentifierModel.communicationUser + = CommunicationUserIdentifierModel.fromJson(reader); + } else if ("phoneNumber".equals(fieldName)) { + deserializedCommunicationIdentifierModel.phoneNumber = PhoneNumberIdentifierModel.fromJson(reader); + } else if ("microsoftTeamsUser".equals(fieldName)) { + deserializedCommunicationIdentifierModel.microsoftTeamsUser + = MicrosoftTeamsUserIdentifierModel.fromJson(reader); + } else if ("microsoftTeamsApp".equals(fieldName)) { + deserializedCommunicationIdentifierModel.microsoftTeamsApp + = MicrosoftTeamsAppIdentifierModel.fromJson(reader); + } else { + reader.skipChildren(); + } + } + + return deserializedCommunicationIdentifierModel; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationIdentifierModelKind.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationIdentifierModelKind.java index 5ef1f17830a7..05bf437af4e0 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationIdentifierModelKind.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationIdentifierModelKind.java @@ -5,7 +5,6 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.util.ExpandableStringEnum; -import com.fasterxml.jackson.annotation.JsonCreator; import java.util.Collection; /** @@ -52,7 +51,6 @@ public CommunicationIdentifierModelKind() { * @param name a name to look for. * @return the corresponding CommunicationIdentifierModelKind. */ - @JsonCreator public static CommunicationIdentifierModelKind fromString(String name) { return fromString(name, CommunicationIdentifierModelKind.class); } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationUserIdentifierModel.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationUserIdentifierModel.java index 272519faa44a..c4b659c6510b 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationUserIdentifierModel.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationUserIdentifierModel.java @@ -5,17 +5,20 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -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; /** * A user that got created with an Azure Communication Services resource. */ @Fluent -public final class CommunicationUserIdentifierModel { +public final class CommunicationUserIdentifierModel implements JsonSerializable { /* * The Id of the communication user. */ - @JsonProperty(value = "id", required = true) private String id; /** @@ -43,4 +46,42 @@ public CommunicationUserIdentifierModel setId(String id) { this.id = id; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("id", this.id); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of CommunicationUserIdentifierModel from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of CommunicationUserIdentifierModel 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 CommunicationUserIdentifierModel. + */ + public static CommunicationUserIdentifierModel fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + CommunicationUserIdentifierModel deserializedCommunicationUserIdentifierModel + = new CommunicationUserIdentifierModel(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("id".equals(fieldName)) { + deserializedCommunicationUserIdentifierModel.id = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedCommunicationUserIdentifierModel; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CreateChatThreadOptions.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CreateChatThreadOptions.java index a0d57d14ecc1..6bdcf94a3bb2 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CreateChatThreadOptions.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CreateChatThreadOptions.java @@ -5,24 +5,26 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -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; /** * Request payload for creating a chat thread. */ @Fluent -public final class CreateChatThreadOptions { +public final class CreateChatThreadOptions implements JsonSerializable { /* * The chat thread topic. */ - @JsonProperty(value = "topic", required = true) private String topic; /* * Participants to be added to the chat thread. */ - @JsonProperty(value = "participants") private List participants; /** @@ -70,4 +72,45 @@ public CreateChatThreadOptions setParticipants(List participant this.participants = participants; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("topic", this.topic); + jsonWriter.writeArrayField("participants", this.participants, (writer, element) -> writer.writeJson(element)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of CreateChatThreadOptions from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of CreateChatThreadOptions 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 CreateChatThreadOptions. + */ + public static CreateChatThreadOptions fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + CreateChatThreadOptions deserializedCreateChatThreadOptions = new CreateChatThreadOptions(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("topic".equals(fieldName)) { + deserializedCreateChatThreadOptions.topic = reader.getString(); + } else if ("participants".equals(fieldName)) { + List participants = reader.readArray(reader1 -> ChatParticipant.fromJson(reader1)); + deserializedCreateChatThreadOptions.participants = participants; + } else { + reader.skipChildren(); + } + } + + return deserializedCreateChatThreadOptions; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CreateChatThreadResult.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CreateChatThreadResult.java index 0e8afb58bb96..741af7860660 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CreateChatThreadResult.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CreateChatThreadResult.java @@ -5,24 +5,26 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -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; /** * Result of the create chat thread operation. */ @Fluent -public final class CreateChatThreadResult { +public final class CreateChatThreadResult implements JsonSerializable { /* * Chat thread. */ - @JsonProperty(value = "chatThread") private ChatThreadProperties chatThread; /* * The participants that failed to be added to the chat thread. */ - @JsonProperty(value = "invalidParticipants", access = JsonProperty.Access.WRITE_ONLY) private List invalidParticipants; /** @@ -59,4 +61,44 @@ public CreateChatThreadResult setChatThread(ChatThreadProperties chatThread) { public List getInvalidParticipants() { return this.invalidParticipants; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeJsonField("chatThread", this.chatThread); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of CreateChatThreadResult from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of CreateChatThreadResult if the JsonReader was pointing to an instance of it, or null if it + * was pointing to JSON null. + * @throws IOException If an error occurs while reading the CreateChatThreadResult. + */ + public static CreateChatThreadResult fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + CreateChatThreadResult deserializedCreateChatThreadResult = new CreateChatThreadResult(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("chatThread".equals(fieldName)) { + deserializedCreateChatThreadResult.chatThread = ChatThreadProperties.fromJson(reader); + } else if ("invalidParticipants".equals(fieldName)) { + List invalidParticipants + = reader.readArray(reader1 -> CommunicationError.fromJson(reader1)); + deserializedCreateChatThreadResult.invalidParticipants = invalidParticipants; + } else { + reader.skipChildren(); + } + } + + return deserializedCreateChatThreadResult; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/IndividualStatusResponse.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/IndividualStatusResponse.java index 1373c735cbba..f940fb4dcdfd 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/IndividualStatusResponse.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/IndividualStatusResponse.java @@ -5,15 +5,19 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Immutable; -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 IndividualStatusResponse model. */ @Immutable -public final class IndividualStatusResponse { +public final class IndividualStatusResponse implements JsonSerializable { /* * Identifies the resource to which the individual status corresponds. */ - @JsonProperty(value = "id", access = JsonProperty.Access.WRITE_ONLY) private String id; /* @@ -26,21 +30,18 @@ public final class IndividualStatusResponse { * 403 for lacking permission to execute the operation, * 404 for resource not found. */ - @JsonProperty(value = "statusCode", access = JsonProperty.Access.WRITE_ONLY) private Integer statusCode; /* * The message explaining why the operation failed for the resource * identified by the key; null if the operation succeeded. */ - @JsonProperty(value = "message", access = JsonProperty.Access.WRITE_ONLY) private String message; /* * Identifies the type of the resource to which the individual status * corresponds. */ - @JsonProperty(value = "type", access = JsonProperty.Access.WRITE_ONLY) private String type; /** @@ -82,4 +83,43 @@ public String getMessage() { public String getType() { return this.type; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of SendChatMessageOptions from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of SendChatMessageOptions if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the SendChatMessageOptions. + */ + public static IndividualStatusResponse fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + final IndividualStatusResponse response = new IndividualStatusResponse(); + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("id".equals(fieldName)) { + response.id = reader.getString(); + } else if ("statusCode".equals(fieldName)) { + response.statusCode = reader.getNullable(JsonReader::getInt); + } else if ("message".equals(fieldName)) { + response.message = reader.getString(); + } else if ("type".equals(fieldName)) { + response.type = reader.getString(); + } else { + reader.skipChildren(); + } + } + return response; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/MicrosoftTeamsAppIdentifierModel.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/MicrosoftTeamsAppIdentifierModel.java index 0e052e632ba6..a354791ae301 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/MicrosoftTeamsAppIdentifierModel.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/MicrosoftTeamsAppIdentifierModel.java @@ -5,23 +5,25 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -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; /** * A Microsoft Teams application. */ @Fluent -public final class MicrosoftTeamsAppIdentifierModel { +public final class MicrosoftTeamsAppIdentifierModel implements JsonSerializable { /* * The Id of the Microsoft Teams application. */ - @JsonProperty(value = "appId", required = true) private String appId; /* * The cloud that the Microsoft Teams application belongs to. By default 'public' if missing. */ - @JsonProperty(value = "cloud") private CommunicationCloudEnvironmentModel cloud; /** @@ -71,4 +73,46 @@ public MicrosoftTeamsAppIdentifierModel setCloud(CommunicationCloudEnvironmentMo this.cloud = cloud; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("appId", this.appId); + jsonWriter.writeStringField("cloud", this.cloud == null ? null : this.cloud.toString()); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of MicrosoftTeamsAppIdentifierModel from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of MicrosoftTeamsAppIdentifierModel 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 MicrosoftTeamsAppIdentifierModel. + */ + public static MicrosoftTeamsAppIdentifierModel fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + MicrosoftTeamsAppIdentifierModel deserializedMicrosoftTeamsAppIdentifierModel + = new MicrosoftTeamsAppIdentifierModel(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("appId".equals(fieldName)) { + deserializedMicrosoftTeamsAppIdentifierModel.appId = reader.getString(); + } else if ("cloud".equals(fieldName)) { + deserializedMicrosoftTeamsAppIdentifierModel.cloud + = CommunicationCloudEnvironmentModel.fromString(reader.getString()); + } else { + reader.skipChildren(); + } + } + + return deserializedMicrosoftTeamsAppIdentifierModel; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/MicrosoftTeamsUserIdentifierModel.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/MicrosoftTeamsUserIdentifierModel.java index b222fbd5ca03..56b631614cb0 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/MicrosoftTeamsUserIdentifierModel.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/MicrosoftTeamsUserIdentifierModel.java @@ -5,29 +5,30 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -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; /** * A Microsoft Teams user. */ @Fluent -public final class MicrosoftTeamsUserIdentifierModel { +public final class MicrosoftTeamsUserIdentifierModel implements JsonSerializable { /* * The Id of the Microsoft Teams user. If not anonymous, this is the AAD object Id of the user. */ - @JsonProperty(value = "userId", required = true) private String userId; /* * True if the Microsoft Teams user is anonymous. By default false if missing. */ - @JsonProperty(value = "isAnonymous") private Boolean isAnonymous; /* * The cloud that the Microsoft Teams user belongs to. By default 'public' if missing. */ - @JsonProperty(value = "cloud") private CommunicationCloudEnvironmentModel cloud; /** @@ -97,4 +98,50 @@ public MicrosoftTeamsUserIdentifierModel setCloud(CommunicationCloudEnvironmentM this.cloud = cloud; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("userId", this.userId); + jsonWriter.writeBooleanField("isAnonymous", this.isAnonymous); + jsonWriter.writeStringField("cloud", this.cloud == null ? null : this.cloud.toString()); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of MicrosoftTeamsUserIdentifierModel from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of MicrosoftTeamsUserIdentifierModel 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 MicrosoftTeamsUserIdentifierModel. + */ + public static MicrosoftTeamsUserIdentifierModel fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + MicrosoftTeamsUserIdentifierModel deserializedMicrosoftTeamsUserIdentifierModel + = new MicrosoftTeamsUserIdentifierModel(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("userId".equals(fieldName)) { + deserializedMicrosoftTeamsUserIdentifierModel.userId = reader.getString(); + } else if ("isAnonymous".equals(fieldName)) { + deserializedMicrosoftTeamsUserIdentifierModel.isAnonymous + = reader.getNullable(JsonReader::getBoolean); + } else if ("cloud".equals(fieldName)) { + deserializedMicrosoftTeamsUserIdentifierModel.cloud + = CommunicationCloudEnvironmentModel.fromString(reader.getString()); + } else { + reader.skipChildren(); + } + } + + return deserializedMicrosoftTeamsUserIdentifierModel; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/MultiStatusResponse.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/MultiStatusResponse.java index 7c72b14b40dd..dac08107f476 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/MultiStatusResponse.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/MultiStatusResponse.java @@ -5,16 +5,20 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Immutable; -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 MultiStatusResponse model. */ @Immutable -public final class MultiStatusResponse { +public final class MultiStatusResponse implements JsonSerializable { /* * The list of status information for each resource in the request. */ - @JsonProperty(value = "multipleStatus", access = JsonProperty.Access.WRITE_ONLY) private List multipleStatus; /** @@ -25,4 +29,37 @@ public final class MultiStatusResponse { public List getMultipleStatus() { return this.multipleStatus; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of SendChatMessageOptions from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of SendChatMessageOptions if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the SendChatMessageOptions. + */ + public static MultiStatusResponse fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + final MultiStatusResponse response = new MultiStatusResponse(); + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("multipleStatus".equals(fieldName)) { + response.multipleStatus = reader.readArray(IndividualStatusResponse::fromJson); + } else { + reader.skipChildren(); + } + } + return response; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/PhoneNumberIdentifierModel.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/PhoneNumberIdentifierModel.java index 9d54537d32a2..4a0cdd678a46 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/PhoneNumberIdentifierModel.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/PhoneNumberIdentifierModel.java @@ -5,17 +5,20 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -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; /** * A phone number. */ @Fluent -public final class PhoneNumberIdentifierModel { +public final class PhoneNumberIdentifierModel implements JsonSerializable { /* * The phone number in E.164 format. */ - @JsonProperty(value = "value", required = true) private String value; /** @@ -43,4 +46,41 @@ public PhoneNumberIdentifierModel setValue(String value) { this.value = value; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("value", this.value); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of PhoneNumberIdentifierModel from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of PhoneNumberIdentifierModel 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 PhoneNumberIdentifierModel. + */ + public static PhoneNumberIdentifierModel fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + PhoneNumberIdentifierModel deserializedPhoneNumberIdentifierModel = new PhoneNumberIdentifierModel(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("value".equals(fieldName)) { + deserializedPhoneNumberIdentifierModel.value = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedPhoneNumberIdentifierModel; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/SendReadReceiptRequest.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/SendReadReceiptRequest.java index e56d652fc422..f79599c2bc0a 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/SendReadReceiptRequest.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/SendReadReceiptRequest.java @@ -5,17 +5,20 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -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; /** * Request payload for sending a read receipt. */ @Fluent -public final class SendReadReceiptRequest { +public final class SendReadReceiptRequest implements JsonSerializable { /* * Id of the latest chat message read by the user. */ - @JsonProperty(value = "chatMessageId", required = true) private String chatMessageId; /** @@ -43,4 +46,41 @@ public SendReadReceiptRequest setChatMessageId(String chatMessageId) { this.chatMessageId = chatMessageId; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("chatMessageId", this.chatMessageId); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of SendReadReceiptRequest from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of SendReadReceiptRequest 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 SendReadReceiptRequest. + */ + public static SendReadReceiptRequest fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + SendReadReceiptRequest deserializedSendReadReceiptRequest = new SendReadReceiptRequest(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("chatMessageId".equals(fieldName)) { + deserializedSendReadReceiptRequest.chatMessageId = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedSendReadReceiptRequest; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/AddChatParticipantsResult.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/AddChatParticipantsResult.java index c1ccd17f51b8..be5010e80684 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/AddChatParticipantsResult.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/AddChatParticipantsResult.java @@ -5,18 +5,22 @@ package com.azure.communication.chat.models; import com.azure.core.annotation.Immutable; -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; /** * Result of the add chat participants operation. */ @Immutable -public final class AddChatParticipantsResult { +public final class AddChatParticipantsResult implements JsonSerializable { /** * The participants that failed to be added to the chat thread. */ - @JsonProperty(value = "invalidParticipants", access = JsonProperty.Access.WRITE_ONLY) private List invalidParticipants; /** @@ -36,4 +40,38 @@ public AddChatParticipantsResult(List invalidParticipants) { public List getInvalidParticipants() { return this.invalidParticipants; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + // Not serializing 'invalidParticipants' as it is json read only. + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of AddChatParticipantsResult from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of AddChatParticipantsResult if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the AddChatParticipantsResult. + */ + public static AddChatParticipantsResult fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + List invalidParticipants = null; + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("invalidParticipants".equals(fieldName)) { + invalidParticipants = reader.readArray(ChatError::fromJson); + } else { + reader.skipChildren(); + } + } + return new AddChatParticipantsResult(invalidParticipants); + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatAttachment.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatAttachment.java index 1ee4e757a5ea..2948a639e17e 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatAttachment.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatAttachment.java @@ -4,12 +4,18 @@ package com.azure.communication.chat.models; import com.azure.core.annotation.Fluent; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; + +import java.io.IOException; /** * An attachment in a chat message. */ @Fluent -public final class ChatAttachment { +public final class ChatAttachment implements JsonSerializable { /** * Id of the attachment */ @@ -125,4 +131,57 @@ public ChatAttachment setPreviewUrl(String previewUrl) { this.previewUrl = previewUrl; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("id", id); + jsonWriter.writeStringField("attachmentType", attachmentType != null ? attachmentType.toString() : null); + jsonWriter.writeStringField("name", name); + jsonWriter.writeStringField("url", url); + jsonWriter.writeStringField("previewUrl", previewUrl); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatAttachment from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatAttachment if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the ChatAttachment. + */ + public static ChatAttachment fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + String id = null; + ChatAttachmentType attachmentType = null; + String name = null; + String url = null; + String previewUrl = null; + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("id".equals(fieldName)) { + id = reader.getString(); + } else if ("attachmentType".equals(fieldName)) { + attachmentType = ChatAttachmentType.fromString(reader.getString()); + } else if ("name".equals(fieldName)) { + name = reader.getString(); + } else if ("url".equals(fieldName)) { + url = reader.getString(); + } else if ("previewUrl".equals(fieldName)) { + previewUrl = reader.getString(); + } else { + reader.skipChildren(); + } + } + return new ChatAttachment(id, attachmentType) + .setName(name) + .setUrl(url) + .setPreviewUrl(previewUrl); + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatAttachmentType.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatAttachmentType.java index 07bc66d49b5b..c174bd36e29f 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatAttachmentType.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatAttachmentType.java @@ -4,7 +4,6 @@ package com.azure.communication.chat.models; import com.azure.core.util.ExpandableStringEnum; -import com.fasterxml.jackson.annotation.JsonCreator; import java.util.Collection; /** @@ -23,7 +22,6 @@ public final class ChatAttachmentType extends ExpandableStringEnum { private final String code; @@ -83,4 +89,53 @@ public ChatError getInnerError() { return this.innerError; } + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("code", code); + jsonWriter.writeStringField("message", message); + jsonWriter.writeStringField("target", target); + jsonWriter.writeArrayField("details", details, (writer, error) -> error.toJson(writer)); + jsonWriter.writeJsonField("innerError", innerError); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatError from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatError if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the ChatError. + */ + public static ChatError fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + String code = null; + String message = null; + String target = null; + List details = null; + ChatError innerError = null; + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("code".equals(fieldName)) { + code = reader.getString(); + } else if ("message".equals(fieldName)) { + message = reader.getString(); + } else if ("target".equals(fieldName)) { + target = reader.getString(); + } else if ("details".equals(fieldName)) { + details = reader.readArray(ChatError::fromJson); + } else if ("innerError".equals(fieldName)) { + innerError = ChatError.fromJson(reader); + } else { + reader.skipChildren(); + } + } + return new ChatError(message, code, target, details, innerError); + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessage.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessage.java index bda1ef5edf7e..39adb8c13827 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessage.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessage.java @@ -3,9 +3,17 @@ package com.azure.communication.chat.models; +import com.azure.communication.chat.implementation.converters.CommunicationIdentifierConverter; +import com.azure.communication.chat.implementation.models.CommunicationIdentifierModel; import com.azure.communication.common.CommunicationIdentifier; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.azure.core.util.CoreUtils; +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.time.OffsetDateTime; import java.util.Map; @@ -13,44 +21,38 @@ * The ChatMessage model. */ @Fluent -public final class ChatMessage { +public final class ChatMessage implements JsonSerializable { /** * The id of the chat message. */ - @JsonProperty(value = "id", required = true) private String id; /** * Type of the chat message. * */ - @JsonProperty(value = "type", required = true) private ChatMessageType type; /** * Version of the chat message. */ - @JsonProperty(value = "version", required = true) private String version; /** * Content of the chat message. */ - @JsonProperty(value = "content") private ChatMessageContent content; /** * The display name of the chat message sender. This property is used to * populate sender name for push notifications. */ - @JsonProperty(value = "senderDisplayName") private String senderDisplayName; /** * The timestamp when the chat message arrived at the server. The timestamp * is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "createdOn") private OffsetDateTime createdOn; /** @@ -59,27 +61,23 @@ public final class ChatMessage { * model must be interpreted as a union: Apart from rawId, at most one * further property may be set. */ - @JsonProperty(value = "senderCommunicationIdentifier") private CommunicationIdentifier sender; /** * The timestamp when the chat message was deleted. The timestamp is in * RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "deletedOn") private OffsetDateTime deletedOn; /** * The timestamp when the chat message was edited. The timestamp is in * RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "editedOn") private OffsetDateTime editedOn; /** * Message metadata. */ - @JsonProperty(value = "metadata") private Map metadata; /** @@ -297,4 +295,75 @@ public ChatMessage setMetadata(Map metadata) { this.metadata = metadata; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("id", id); + jsonWriter.writeStringField("type", type != null ? type.toString() : null); + jsonWriter.writeJsonField("content", content); + jsonWriter.writeStringField("senderDisplayName", senderDisplayName); + jsonWriter.writeStringField("createdOn", createdOn != null ? createdOn.toString() : null); + // final CommunicationIdentifierModel identifier = CommunicationIdentifierConverter.convert(sender); + // jsonWriter.writeJsonField("senderCommunicationIdentifier", identifier); + jsonWriter.writeStringField("deletedOn", deletedOn != null ? deletedOn.toString() : null); + jsonWriter.writeStringField("editedOn", editedOn != null ? editedOn.toString() : null); + jsonWriter.writeMapField("metadata", metadata, JsonWriter::writeString); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of SendChatMessageOptions from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of SendChatMessageOptions if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the SendChatMessageOptions. + */ + public static ChatMessage fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + final ChatMessage message = new ChatMessage(); + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("id".equals(fieldName)) { + message.setId(reader.getString()); + } else if ("type".equals(fieldName)) { + message.setType(ChatMessageType.fromString(reader.getString())); + } else if ("version".equals(fieldName)) { + message.setVersion(reader.getString()); + } else if ("content".equals(fieldName)) { + message.setContent(ChatMessageContent.fromJson(reader)); + } else if ("senderDisplayName".equals(fieldName)) { + message.setSenderDisplayName(reader.getString()); + } else if ("createdOn".equals(fieldName)) { + final String value = reader.getString(); + if (!CoreUtils.isNullOrEmpty(value)) { + message.setCreatedOn(OffsetDateTime.parse(value)); + } + } else if ("senderCommunicationIdentifier".equals(fieldName)) { + final CommunicationIdentifierModel identifier = reader.readObject(CommunicationIdentifierModel::fromJson); + message.setSender(CommunicationIdentifierConverter.convert(identifier)); + } else if ("deletedOn".equals(fieldName)) { + final String value = reader.getString(); + if (!CoreUtils.isNullOrEmpty(value)) { + message.setDeletedOn(OffsetDateTime.parse(value)); + } + } else if ("editedOn".equals(fieldName)) { + final String value = reader.getString(); + if (!CoreUtils.isNullOrEmpty(value)) { + message.setEditedOn(OffsetDateTime.parse(value)); + } + } else if ("metadata".equals(fieldName)) { + message.setMetadata(reader.readMap(JsonReader::getString)); + } else { + reader.skipChildren(); + } + } + return message; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageContent.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageContent.java index a5b5320755df..a2471bd41e1a 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageContent.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageContent.java @@ -3,30 +3,33 @@ package com.azure.communication.chat.models; +import com.azure.communication.chat.implementation.converters.CommunicationIdentifierConverter; +import com.azure.communication.chat.implementation.models.CommunicationIdentifierModel; import com.azure.communication.common.CommunicationIdentifier; import com.azure.core.annotation.Fluent; -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; /** * Content of a chat message. */ @Fluent -public final class ChatMessageContent { +public final class ChatMessageContent implements JsonSerializable { - @JsonProperty(value = "message") - private String message; + private final String message; - @JsonProperty(value = "topic") - private String topic; + private final String topic; - @JsonProperty(value = "participants") - private Iterable participants; + private final Iterable participants; - @JsonProperty(value = "attachments") private Iterable attachments; - @JsonProperty(value = "initiatorCommunicationIdentifier") - private CommunicationIdentifier initiator; + private final CommunicationIdentifier initiator; /** * Constructs a new ChatMessageContent @@ -106,4 +109,56 @@ public CommunicationIdentifier getInitiator() { return this.initiator; } + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("message", message); + jsonWriter.writeStringField("topic", topic); + jsonWriter.writeArrayField("participants", participants, (writer, participant) -> participant.toJson(writer)); + jsonWriter.writeArrayField("attachments", attachments, (writer, attachment) -> attachment.toJson(writer)); + // final CommunicationIdentifierModel identifier = CommunicationIdentifierConverter.convert(initiator); + // jsonWriter.writeJsonField("initiatorCommunicationIdentifier", identifier); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatMessageContent from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatMessageContent if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the ChatMessageContent. + */ + public static ChatMessageContent fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + String message = null; + String topic = null; + List participants = null; + List attachments = null; + CommunicationIdentifier initiator = null; + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("message".equals(fieldName)) { + message = reader.getString(); + } else if ("topic".equals(fieldName)) { + topic = reader.getString(); + } else if ("participants".equals(fieldName)) { + participants = reader.readArray(ChatParticipant::fromJson); + } else if ("attachments".equals(fieldName)) { + attachments = reader.readArray(ChatAttachment::fromJson); + } else if ("initiatorCommunicationIdentifier".equals(fieldName)) { + final CommunicationIdentifierModel identifier = reader.readObject(CommunicationIdentifierModel::fromJson); + initiator = CommunicationIdentifierConverter.convert(identifier); + } else { + reader.skipChildren(); + } + } + return new ChatMessageContent(message, topic, participants, initiator) + .setAttachments(attachments); + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageReadReceipt.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageReadReceipt.java index da7a9028e507..2e379e0d1dc3 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageReadReceipt.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageReadReceipt.java @@ -3,37 +3,42 @@ package com.azure.communication.chat.models; +import com.azure.communication.chat.implementation.converters.CommunicationIdentifierConverter; +import com.azure.communication.chat.implementation.models.CommunicationIdentifierModel; import com.azure.communication.common.CommunicationIdentifier; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.azure.core.util.CoreUtils; +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.time.OffsetDateTime; /** * The ChatMessageReadReceipt model. */ @Fluent -public final class ChatMessageReadReceipt { +public final class ChatMessageReadReceipt implements JsonSerializable { /** * Identifies a participant in Azure Communication services. A participant * is, for example, a phone number or an Azure communication user. This * model must be interpreted as a union: Apart from rawId, at most one * further property may be set. */ - @JsonProperty(value = "senderCommunicationIdentifier", access = JsonProperty.Access.WRITE_ONLY) private CommunicationIdentifier sender; /** * Id for the chat message that has been read. This id is generated by the * server. */ - @JsonProperty(value = "chatMessageId", access = JsonProperty.Access.WRITE_ONLY) private String chatMessageId; /** * Read receipt timestamp. The timestamp is in RFC3339 format: * `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "readOn", access = JsonProperty.Access.WRITE_ONLY) private OffsetDateTime readOn; /** @@ -99,4 +104,46 @@ public ChatMessageReadReceipt setReadOn(OffsetDateTime readOn) { this.readOn = readOn; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + // Not serializing any properties, all are json read only. + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of AddChatParticipantsResult from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of AddChatParticipantsResult if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the AddChatParticipantsResult. + */ + public static ChatMessageReadReceipt fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + final ChatMessageReadReceipt receipt = new ChatMessageReadReceipt(); + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("senderCommunicationIdentifier".equals(fieldName)) { + final CommunicationIdentifierModel identifier = reader.readObject(CommunicationIdentifierModel::fromJson); + receipt.setSender(CommunicationIdentifierConverter.convert(identifier)); + } else if ("chatMessageId".equals(fieldName)) { + receipt.setChatMessageId(reader.getString()); + } else if ("readOn".equals(fieldName)) { + final String value = reader.getString(); + if (!CoreUtils.isNullOrEmpty(value)) { + receipt.setReadOn(OffsetDateTime.parse(value)); + } + } else { + reader.skipChildren(); + } + } + return receipt; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageType.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageType.java index 7df4a08f66f2..2f7fe9f7049b 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageType.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageType.java @@ -5,7 +5,6 @@ package com.azure.communication.chat.models; import com.azure.core.util.ExpandableStringEnum; -import com.fasterxml.jackson.annotation.JsonCreator; import java.util.Collection; /** @@ -52,7 +51,6 @@ public ChatMessageType() { * @param name a name to look for. * @return the corresponding ChatMessageType. */ - @JsonCreator public static ChatMessageType fromString(String name) { return fromString(name, ChatMessageType.class); } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatParticipant.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatParticipant.java index 1912de23b5b9..90b98159e0be 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatParticipant.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatParticipant.java @@ -3,36 +3,40 @@ package com.azure.communication.chat.models; +import com.azure.communication.chat.implementation.converters.CommunicationIdentifierConverter; +import com.azure.communication.chat.implementation.models.CommunicationIdentifierModel; import com.azure.communication.common.CommunicationIdentifier; import com.azure.core.annotation.Fluent; -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.time.OffsetDateTime; /** * The ChatParticipant model. */ @Fluent -public final class ChatParticipant { +public final class ChatParticipant implements JsonSerializable { /** * Identifies a participant in Azure Communication services. A participant * is, for example, a phone number or an Azure communication user. This * model must be interpreted as a union: Apart from rawId, at most one * further property may be set. */ - @JsonProperty(value = "communicationIdentifier", required = true) private CommunicationIdentifier communicationIdentifier; /** * Display name for the chat participant. */ - @JsonProperty(value = "displayName") private String displayName; /** * Time from which the chat history is shared with the member. The * timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "shareHistoryTime") private OffsetDateTime shareHistoryTime; /** @@ -100,4 +104,46 @@ public ChatParticipant setShareHistoryTime(OffsetDateTime shareHistoryTime) { this.shareHistoryTime = shareHistoryTime; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + final CommunicationIdentifierModel identifier = CommunicationIdentifierConverter.convert(communicationIdentifier); + jsonWriter.writeJsonField("communicationIdentifier", identifier); + jsonWriter.writeStringField("displayName", displayName); + jsonWriter.writeStringField("startDateTime", shareHistoryTime.toString()); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ParticipantsUpdated from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ParticipantsUpdated if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the ParticipantsUpdated. + */ + public static ChatParticipant fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + final ChatParticipant participant = new ChatParticipant(); + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("communicationIdentifier".equals(fieldName)) { + final CommunicationIdentifierModel identifier = reader.readObject(CommunicationIdentifierModel::fromJson); + participant.communicationIdentifier = CommunicationIdentifierConverter.convert(identifier); + } else if ("displayName".equals(fieldName)) { + participant.displayName = reader.getString(); + } else if ("startDateTime".equals(fieldName)) { + participant.shareHistoryTime = OffsetDateTime.parse(reader.getString()); + } else { + reader.skipChildren(); + } + } + return participant; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatThreadItem.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatThreadItem.java index cb1d2e941513..444896453f99 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatThreadItem.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatThreadItem.java @@ -5,37 +5,39 @@ package com.azure.communication.chat.models; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.azure.core.util.CoreUtils; +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.time.OffsetDateTime; +import java.time.format.DateTimeFormatter; /** * Summary information of a chat thread. */ @Fluent -public final class ChatThreadItem { +public final class ChatThreadItem implements JsonSerializable { /* * Chat thread id. */ - @JsonProperty(value = "id", required = true) private String id; /* * Chat thread topic. */ - @JsonProperty(value = "topic", required = true) private String topic; /* * The timestamp when the chat thread was deleted. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "deletedOn") private OffsetDateTime deletedOn; /* * The timestamp when the last message arrived at the server. The timestamp is in RFC3339 format: * `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "lastMessageReceivedOn", access = JsonProperty.Access.WRITE_ONLY) private OffsetDateTime lastMessageReceivedOn; /** @@ -115,4 +117,52 @@ public ChatThreadItem setDeletedOn(OffsetDateTime deletedOn) { public OffsetDateTime getLastMessageReceivedOn() { return this.lastMessageReceivedOn; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("id", this.id); + jsonWriter.writeStringField("topic", this.topic); + jsonWriter.writeStringField("deletedOn", + this.deletedOn == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.deletedOn)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatThreadItem from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatThreadItem 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 ChatThreadItem. + */ + public static ChatThreadItem fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ChatThreadItem deserializedChatThreadItem = new ChatThreadItem(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("id".equals(fieldName)) { + deserializedChatThreadItem.id = reader.getString(); + } else if ("topic".equals(fieldName)) { + deserializedChatThreadItem.topic = reader.getString(); + } else if ("deletedOn".equals(fieldName)) { + deserializedChatThreadItem.deletedOn = reader + .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString())); + } else if ("lastMessageReceivedOn".equals(fieldName)) { + deserializedChatThreadItem.lastMessageReceivedOn = reader + .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString())); + } else { + reader.skipChildren(); + } + } + + return deserializedChatThreadItem; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatThreadProperties.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatThreadProperties.java index c8f6b513fa85..5e89ff2f1178 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatThreadProperties.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatThreadProperties.java @@ -3,16 +3,24 @@ package com.azure.communication.chat.models; +import com.azure.communication.chat.implementation.converters.CommunicationIdentifierConverter; +import com.azure.communication.chat.implementation.models.CommunicationIdentifierModel; import com.azure.communication.common.CommunicationIdentifier; import com.azure.core.annotation.Fluent; +import com.azure.core.util.CoreUtils; +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.time.OffsetDateTime; /** * The ChatThread model. */ @Fluent -public final class ChatThreadProperties { +public final class ChatThreadProperties implements JsonSerializable { private String id; @@ -107,4 +115,52 @@ public ChatThreadProperties setCreatedBy(CommunicationIdentifier createdBy) { this.createdBy = createdBy; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("id", id); + jsonWriter.writeStringField("topic", topic); + jsonWriter.writeStringField("createdOn", createdOn != null ? createdOn.toString() : null); + final CommunicationIdentifierModel identifier = CommunicationIdentifierConverter.convert(createdBy); + jsonWriter.writeJsonField("createdBy", identifier); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatThreadProperties from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatThreadProperties if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the ChatThreadProperties. + */ + public static ChatThreadProperties fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + final ChatThreadProperties properties = new ChatThreadProperties(); + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("id".equals(fieldName)) { + properties.setId(reader.getString()); + } else if ("topic".equals(fieldName)) { + properties.setTopic(reader.getString()); + } else if ("createdOn".equals(fieldName)) { + final String value = reader.getString(); + if (!CoreUtils.isNullOrEmpty(value)) { + properties.setCreatedOn(OffsetDateTime.parse(value)); + } + } else if ("createdBy".equals(fieldName)) { + final CommunicationIdentifierModel identifier = reader.readObject(CommunicationIdentifierModel::fromJson); + properties.setCreatedBy(CommunicationIdentifierConverter.convert(identifier)); + } else { + reader.skipChildren(); + } + } + return properties; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/CreateChatThreadResult.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/CreateChatThreadResult.java index df3dbdb3c4a9..8f1c0dcb089c 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/CreateChatThreadResult.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/CreateChatThreadResult.java @@ -4,25 +4,27 @@ package com.azure.communication.chat.models; import com.azure.core.annotation.Fluent; -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 CreateChatThreadResult model. */ @Fluent -public final class CreateChatThreadResult { +public final class CreateChatThreadResult implements JsonSerializable { /** * The thread property. */ - @JsonProperty(value = "chatThread") private ChatThreadProperties chatThreadProperties; /** * The participants that failed to be added to the chat thread. */ - @JsonProperty(value = "invalidParticipants", access = JsonProperty.Access.WRITE_ONLY) private List invalidParticipants; /** @@ -54,4 +56,41 @@ public List getInvalidParticipants() { return this.invalidParticipants; } + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeJsonField("chatThread", chatThreadProperties); + // Not serializing 'invalidParticipants' as it is json read only. + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of AddChatParticipantsResult from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of AddChatParticipantsResult if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the AddChatParticipantsResult. + */ + public static CreateChatThreadResult fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ChatThreadProperties chatThreadProperties = null; + List invalidParticipants = null; + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("chatThread".equals(fieldName)) { + chatThreadProperties = ChatThreadProperties.fromJson(reader); + } else if ("invalidParticipants".equals(fieldName)) { + invalidParticipants = reader.readArray(ChatError::fromJson); + } else { + reader.skipChildren(); + } + } + return new CreateChatThreadResult(chatThreadProperties, invalidParticipants); + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/SendChatMessageOptions.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/SendChatMessageOptions.java index 8790c6c1173d..cd10d2f2e07c 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/SendChatMessageOptions.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/SendChatMessageOptions.java @@ -5,37 +5,37 @@ package com.azure.communication.chat.models; import com.azure.core.annotation.Fluent; -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.Map; /** * Details of the message to send. */ @Fluent -public final class SendChatMessageOptions { +public final class SendChatMessageOptions implements JsonSerializable { /* * Chat message content. */ - @JsonProperty(value = "content", required = true) private String content; /* * The display name of the chat message sender. This property is used to populate sender name for push * notifications. */ - @JsonProperty(value = "senderDisplayName") private String senderDisplayName; /* * The chat message type. */ - @JsonProperty(value = "type") private ChatMessageType type; /* * Message metadata. */ - @JsonProperty(value = "metadata") private Map metadata; /** @@ -125,4 +125,51 @@ public SendChatMessageOptions setMetadata(Map metadata) { this.metadata = metadata; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("content", this.content); + jsonWriter.writeStringField("senderDisplayName", this.senderDisplayName); + jsonWriter.writeStringField("type", this.type == null ? null : this.type.toString()); + jsonWriter.writeMapField("metadata", this.metadata, (writer, element) -> writer.writeString(element)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of SendChatMessageOptions from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of SendChatMessageOptions 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 SendChatMessageOptions. + */ + public static SendChatMessageOptions fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + SendChatMessageOptions deserializedSendChatMessageOptions = new SendChatMessageOptions(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("content".equals(fieldName)) { + deserializedSendChatMessageOptions.content = reader.getString(); + } else if ("senderDisplayName".equals(fieldName)) { + deserializedSendChatMessageOptions.senderDisplayName = reader.getString(); + } else if ("type".equals(fieldName)) { + deserializedSendChatMessageOptions.type = ChatMessageType.fromString(reader.getString()); + } else if ("metadata".equals(fieldName)) { + Map metadata = reader.readMap(reader1 -> reader1.getString()); + deserializedSendChatMessageOptions.metadata = metadata; + } else { + reader.skipChildren(); + } + } + + return deserializedSendChatMessageOptions; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/SendChatMessageResult.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/SendChatMessageResult.java index b8f4503fc996..5948cfda650b 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/SendChatMessageResult.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/SendChatMessageResult.java @@ -5,17 +5,20 @@ package com.azure.communication.chat.models; import com.azure.core.annotation.Fluent; -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; /** * Result of the send message operation. */ @Fluent -public final class SendChatMessageResult { +public final class SendChatMessageResult implements JsonSerializable { /* * A server-generated message id. */ - @JsonProperty(value = "id", required = true) private String id; /** @@ -43,4 +46,41 @@ public SendChatMessageResult setId(String id) { this.id = id; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("id", this.id); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of SendChatMessageResult from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of SendChatMessageResult 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 SendChatMessageResult. + */ + public static SendChatMessageResult fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + SendChatMessageResult deserializedSendChatMessageResult = new SendChatMessageResult(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("id".equals(fieldName)) { + deserializedSendChatMessageResult.id = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedSendChatMessageResult; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/TypingNotificationOptions.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/TypingNotificationOptions.java index 81a733ec31ec..41a649e919e1 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/TypingNotificationOptions.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/TypingNotificationOptions.java @@ -5,18 +5,21 @@ package com.azure.communication.chat.models; import com.azure.core.annotation.Fluent; -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; /** * Request payload for typing notifications. */ @Fluent -public final class TypingNotificationOptions { +public final class TypingNotificationOptions implements JsonSerializable { /* * The display name of the typing notification sender. This property is used to populate sender name for push * notifications. */ - @JsonProperty(value = "senderDisplayName") private String senderDisplayName; /** @@ -46,4 +49,40 @@ public TypingNotificationOptions setSenderDisplayName(String senderDisplayName) this.senderDisplayName = senderDisplayName; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("senderDisplayName", this.senderDisplayName); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of TypingNotificationOptions from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of TypingNotificationOptions if the JsonReader was pointing to an instance of it, or null if + * it was pointing to JSON null. + * @throws IOException If an error occurs while reading the TypingNotificationOptions. + */ + public static TypingNotificationOptions fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + TypingNotificationOptions deserializedTypingNotificationOptions = new TypingNotificationOptions(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("senderDisplayName".equals(fieldName)) { + deserializedTypingNotificationOptions.senderDisplayName = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedTypingNotificationOptions; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/UpdateChatMessageOptions.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/UpdateChatMessageOptions.java index 191309e34575..58679fb47a00 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/UpdateChatMessageOptions.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/UpdateChatMessageOptions.java @@ -5,24 +5,26 @@ package com.azure.communication.chat.models; import com.azure.core.annotation.Fluent; -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.Map; /** * Request payload for updating a chat message. */ @Fluent -public final class UpdateChatMessageOptions { +public final class UpdateChatMessageOptions implements JsonSerializable { /* * Chat message content. */ - @JsonProperty(value = "content") private String content; /* * Message metadata. */ - @JsonProperty(value = "metadata") private Map metadata; /** @@ -70,4 +72,44 @@ public UpdateChatMessageOptions setMetadata(Map metadata) { this.metadata = metadata; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("content", this.content); + jsonWriter.writeMapField("metadata", this.metadata, (writer, element) -> writer.writeString(element)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of UpdateChatMessageOptions from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of UpdateChatMessageOptions if the JsonReader was pointing to an instance of it, or null if + * it was pointing to JSON null. + * @throws IOException If an error occurs while reading the UpdateChatMessageOptions. + */ + public static UpdateChatMessageOptions fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + UpdateChatMessageOptions deserializedUpdateChatMessageOptions = new UpdateChatMessageOptions(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("content".equals(fieldName)) { + deserializedUpdateChatMessageOptions.content = reader.getString(); + } else if ("metadata".equals(fieldName)) { + Map metadata = reader.readMap(reader1 -> reader1.getString()); + deserializedUpdateChatMessageOptions.metadata = metadata; + } else { + reader.skipChildren(); + } + } + + return deserializedUpdateChatMessageOptions; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/UpdateChatThreadOptions.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/UpdateChatThreadOptions.java index 505d6f6bbcdb..fa8cf0ec59c4 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/UpdateChatThreadOptions.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/UpdateChatThreadOptions.java @@ -5,17 +5,20 @@ package com.azure.communication.chat.models; import com.azure.core.annotation.Fluent; -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; /** * Request payload for updating a chat thread. */ @Fluent -public final class UpdateChatThreadOptions { +public final class UpdateChatThreadOptions implements JsonSerializable { /* * Chat thread topic. */ - @JsonProperty(value = "topic") private String topic; /** @@ -43,4 +46,40 @@ public UpdateChatThreadOptions setTopic(String topic) { this.topic = topic; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("topic", this.topic); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of UpdateChatThreadOptions from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of UpdateChatThreadOptions if the JsonReader was pointing to an instance of it, or null if it + * was pointing to JSON null. + * @throws IOException If an error occurs while reading the UpdateChatThreadOptions. + */ + public static UpdateChatThreadOptions fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + UpdateChatThreadOptions deserializedUpdateChatThreadOptions = new UpdateChatThreadOptions(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("topic".equals(fieldName)) { + deserializedUpdateChatThreadOptions.topic = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedUpdateChatThreadOptions; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/test/java/com/azure/communication/chat/ChatResponseMocker.java b/sdk/communication/azure-communication-chat/src/test/java/com/azure/communication/chat/ChatResponseMocker.java index 9650d106d835..b4ac8c4c024f 100644 --- a/sdk/communication/azure-communication-chat/src/test/java/com/azure/communication/chat/ChatResponseMocker.java +++ b/sdk/communication/azure-communication-chat/src/test/java/com/azure/communication/chat/ChatResponseMocker.java @@ -3,6 +3,8 @@ package com.azure.communication.chat; +import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; @@ -18,9 +20,11 @@ import com.azure.core.http.HttpRequest; import com.azure.core.http.HttpResponse; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; +import com.azure.json.JsonProviders; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -48,14 +52,7 @@ public static HttpResponse createChatThreadInvalidParticipantResponse(HttpReques .setId("000")) .setInvalidParticipants(invalidParticipants); - ObjectMapper mapper = new ObjectMapper(); - String body = null; - try { - body = mapper.writeValueAsString(result); - } catch (JsonProcessingException e) { - e.printStackTrace(); - } - + final String body = serializeObject(result); return generateMockResponse(body, request, 201); } @@ -67,14 +64,7 @@ public static HttpResponse addParticipantsInvalidParticipantResponse(HttpRequest MockAddChatParticipantsResult result = new MockAddChatParticipantsResult() .setInvalidParticipants(invalidParticipants); - ObjectMapper mapper = new ObjectMapper(); - String body = null; - try { - body = mapper.writeValueAsString(result); - } catch (JsonProcessingException e) { - e.printStackTrace(); - } - + final String body = serializeObject(result); return generateMockResponse(body, request, 201); } @@ -125,12 +115,10 @@ public Mono getBodyAsString(Charset charset) { }; } - static class MockCreateChatThreadResult { + static class MockCreateChatThreadResult implements JsonSerializable { - @JsonProperty(value = "chatThread") private ChatThreadProperties chatThread; - @JsonProperty(value = "invalidParticipants") private List invalidParticipants; public ChatThreadProperties getChatThread() { @@ -150,11 +138,47 @@ public MockCreateChatThreadResult setInvalidParticipants(List error.toJson(writer)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of MockCreateChatThreadResult from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of MockCreateChatThreadResult if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the MockCreateChatThreadResult. + */ + public static MockCreateChatThreadResult fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + final MockCreateChatThreadResult result = new MockCreateChatThreadResult(); + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("chatThread".equals(fieldName)) { + result.setChatThread(ChatThreadProperties.fromJson(jsonReader)); + } else if ("invalidParticipants".equals(fieldName)) { + result.setInvalidParticipants(reader.readArray(MockCommunicationError::fromJson)); + } else { + reader.skipChildren(); + } + } + return result; + }); + } } - static class MockAddChatParticipantsResult { + static class MockAddChatParticipantsResult implements JsonSerializable { - @JsonProperty(value = "invalidParticipants") private List invalidParticipants; public List getInvalidParticipants() { @@ -165,17 +189,48 @@ public MockAddChatParticipantsResult setInvalidParticipants(List error.toJson(writer)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of MockAddChatParticipantsResult from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of MockAddChatParticipantsResult if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the MockAddChatParticipantsResult. + */ + public static MockAddChatParticipantsResult fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + final MockAddChatParticipantsResult result = new MockAddChatParticipantsResult(); + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("invalidParticipants".equals(fieldName)) { + result.setInvalidParticipants(reader.readArray(MockCommunicationError::fromJson)); + } else { + reader.skipChildren(); + } + } + return result; + }); + } } - static class MockCommunicationError { + static class MockCommunicationError implements JsonSerializable { - @JsonProperty(value = "code") private String code; - @JsonProperty(value = "message") private String message; - @JsonProperty(value = "target") private String target; public String getCode() { @@ -204,6 +259,48 @@ public MockCommunicationError setTarget(String target) { this.target = target; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("code", code); + jsonWriter.writeStringField("message", message); + jsonWriter.writeStringField("target", target); + return jsonWriter.writeEndObject(); + } + + public static MockCommunicationError fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + final MockCommunicationError error = new MockCommunicationError(); + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("code".equals(fieldName)) { + error.setCode(reader.getString()); + } else if ("message".equals(fieldName)) { + error.setMessage(reader.getString()); + } else if ("target".equals(fieldName)) { + error.setTarget(reader.getString()); + } else { + reader.skipChildren(); + } + } + return error; + }); + } } + private static String serializeObject(JsonSerializable o) { + try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + JsonWriter writer = JsonProviders.createWriter(outputStream)) { + o.toJson(writer); + writer.flush(); + return outputStream.toString(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } } diff --git a/sdk/communication/azure-communication-chat/swagger/README.md b/sdk/communication/azure-communication-chat/swagger/README.md index 3e20d078f140..b4a23a12bf00 100644 --- a/sdk/communication/azure-communication-chat/swagger/README.md +++ b/sdk/communication/azure-communication-chat/swagger/README.md @@ -36,7 +36,7 @@ To update generated files for chat service, run the following command ```yaml tag: package-chat-2024-03-07 -use: '@autorest/java@4.1.25' +use: '@autorest/java@4.1.33' require: - https://raw.githubusercontent.com/Azure/azure-rest-api-specs/72d4c8cae964a12dc27ad4684b0bddf493225338/specification/communication/data-plane/Chat/readme.md java: true