From c689b6091b5f55eeb6a2aea3f400643c3a8dbad2 Mon Sep 17 00:00:00 2001 From: Anu Thomas Chandy Date: Wed, 31 Jul 2024 15:27:00 +0300 Subject: [PATCH] migrate azure-communication-email to azure-json (#41222) --- .../src/main/resources/revapi/revapi.json | 7 + .../AzureCommunicationEmailServiceImpl.java | 54 +++--- ...eCommunicationEmailServiceImplBuilder.java | 159 +++++++++++------- .../email/implementation/EmailsImpl.java | 126 ++++++-------- .../models/EmailAttachment.java | 103 +++++++++--- .../implementation/models/EmailContent.java | 86 ++++++++-- .../implementation/models/EmailMessage.java | 148 ++++++++++++---- .../models/EmailRecipients.java | 79 +++++++-- .../models/EmailSendResult.java | 100 +++++++++-- .../models/EmailsGetSendResultHeaders.java | 12 +- .../models/EmailsGetSendResultResponse.java | 16 +- .../models/EmailsSendHeaders.java | 17 +- .../models/EmailsSendResponse.java | 16 +- .../models/ErrorAdditionalInfo.java | 62 ++++++- .../implementation/models/ErrorDetail.java | 80 +++++++-- .../implementation/models/ErrorResponse.java | 62 +++++-- .../models/ErrorResponseException.java | 12 +- .../implementation/models/package-info.java | 5 +- .../email/implementation/package-info.java | 5 +- .../email/models/EmailAddress.java | 76 +++++++-- .../email/models/EmailSendResult.java | 61 +++++-- .../email/models/EmailSendStatus.java | 35 ++-- .../email/models/package-info.java | 5 +- .../swagger/README.md | 2 +- 24 files changed, 957 insertions(+), 371 deletions(-) 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 c1585ce4ec2d5..ab18dd74cc319 100644 --- a/eng/code-quality-reports/src/main/resources/revapi/revapi.json +++ b/eng/code-quality-reports/src/main/resources/revapi/revapi.json @@ -544,6 +544,13 @@ "new" : ".*? com\\.azure\\.communication\\.chat\\.models.*", "justification": "Migration to azure-json" }, + { + "regex": true, + "code" : "java\\.annotation\\.removed", + "old" : ".*? com\\.azure\\.communication\\.email\\.models.*", + "new" : ".*? com\\.azure\\.communication\\.email\\.models.*", + "justification": "Migration to azure-json" + }, { "code": "java.class.nowFinal", "old" : "class com.azure.resourcemanager.eventhubs.models.Identity", diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/AzureCommunicationEmailServiceImpl.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/AzureCommunicationEmailServiceImpl.java index 418fd51745049..0dbab18ecf066 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/AzureCommunicationEmailServiceImpl.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/AzureCommunicationEmailServiceImpl.java @@ -6,68 +6,79 @@ import com.azure.core.http.HttpPipeline; import com.azure.core.http.HttpPipelineBuilder; -import com.azure.core.http.policy.CookiePolicy; import com.azure.core.http.policy.RetryPolicy; import com.azure.core.http.policy.UserAgentPolicy; import com.azure.core.util.serializer.JacksonAdapter; import com.azure.core.util.serializer.SerializerAdapter; -/** Initializes a new instance of the AzureCommunicationEmailService type. */ +/** + * Initializes a new instance of the AzureCommunicationEmailService type. + */ public final class AzureCommunicationEmailServiceImpl { - /** The communication resource, for example https://my-resource.communication.azure.com. */ + /** + * The communication resource, for example https://my-resource.communication.azure.com. + */ private final String endpoint; /** * Gets The communication resource, for example https://my-resource.communication.azure.com. - * + * * @return the endpoint value. */ public String getEndpoint() { return this.endpoint; } - /** Api Version. */ + /** + * Api Version. + */ private final String apiVersion; /** * Gets Api Version. - * + * * @return the apiVersion value. */ public String getApiVersion() { return this.apiVersion; } - /** The HTTP pipeline to send requests through. */ + /** + * The HTTP pipeline to send requests through. + */ private final HttpPipeline httpPipeline; /** * Gets The HTTP pipeline to send requests through. - * + * * @return the httpPipeline value. */ public HttpPipeline getHttpPipeline() { return this.httpPipeline; } - /** The serializer to serialize an object into a string. */ + /** + * The serializer to serialize an object into a string. + */ private final SerializerAdapter serializerAdapter; /** * Gets The serializer to serialize an object into a string. - * + * * @return the serializerAdapter value. */ public SerializerAdapter getSerializerAdapter() { return this.serializerAdapter; } - /** The EmailsImpl object to access its operations. */ + /** + * The EmailsImpl object to access its operations. + */ private final EmailsImpl emails; /** * Gets the EmailsImpl object to access its operations. - * + * * @return the EmailsImpl object. */ public EmailsImpl getEmails() { @@ -76,23 +87,18 @@ public EmailsImpl getEmails() { /** * Initializes an instance of AzureCommunicationEmailService client. - * + * * @param endpoint The communication resource, for example https://my-resource.communication.azure.com. * @param apiVersion Api Version. */ AzureCommunicationEmailServiceImpl(String endpoint, String apiVersion) { - this( - new HttpPipelineBuilder() - .policies(new UserAgentPolicy(), new RetryPolicy(), new CookiePolicy()) - .build(), - JacksonAdapter.createDefaultSerializerAdapter(), - endpoint, - apiVersion); + this(new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy()).build(), + JacksonAdapter.createDefaultSerializerAdapter(), endpoint, apiVersion); } /** * Initializes an instance of AzureCommunicationEmailService client. - * + * * @param httpPipeline The HTTP pipeline to send requests through. * @param endpoint The communication resource, for example https://my-resource.communication.azure.com. * @param apiVersion Api Version. @@ -103,14 +109,14 @@ public EmailsImpl getEmails() { /** * Initializes an instance of AzureCommunicationEmailService client. - * + * * @param httpPipeline The HTTP pipeline to send requests through. * @param serializerAdapter The serializer to serialize an object into a string. * @param endpoint The communication resource, for example https://my-resource.communication.azure.com. * @param apiVersion Api Version. */ - AzureCommunicationEmailServiceImpl( - HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, String endpoint, String apiVersion) { + AzureCommunicationEmailServiceImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, String endpoint, + String apiVersion) { this.httpPipeline = httpPipeline; this.serializerAdapter = serializerAdapter; this.endpoint = endpoint; diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/AzureCommunicationEmailServiceImplBuilder.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/AzureCommunicationEmailServiceImplBuilder.java index 203d04202c0c5..e137a68563111 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/AzureCommunicationEmailServiceImplBuilder.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/AzureCommunicationEmailServiceImplBuilder.java @@ -20,9 +20,8 @@ import com.azure.core.http.policy.AddHeadersFromContextPolicy; import com.azure.core.http.policy.AddHeadersPolicy; import com.azure.core.http.policy.AzureKeyCredentialPolicy; -import com.azure.core.http.policy.CookiePolicy; -import com.azure.core.http.policy.HttpLogOptions; 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; @@ -40,24 +39,30 @@ import java.util.Map; import java.util.Objects; -/** A builder for creating a new instance of the AzureCommunicationEmailService type. */ -@ServiceClientBuilder(serviceClients = {AzureCommunicationEmailServiceImpl.class}) -public final class AzureCommunicationEmailServiceImplBuilder - implements HttpTrait, - ConfigurationTrait, - AzureKeyCredentialTrait, - EndpointTrait { - @Generated private static final String SDK_NAME = "name"; +/** + * A builder for creating a new instance of the AzureCommunicationEmailService type. + */ +@ServiceClientBuilder(serviceClients = { AzureCommunicationEmailServiceImpl.class }) +public final class AzureCommunicationEmailServiceImplBuilder implements + HttpTrait, ConfigurationTrait, + AzureKeyCredentialTrait, + EndpointTrait { + @Generated + private static final String SDK_NAME = "name"; - @Generated private static final String SDK_VERSION = "version"; + @Generated + private static final String SDK_VERSION = "version"; @Generated - private static final Map PROPERTIES = - CoreUtils.getProperties("azure-communication-email.properties"); + private static final Map PROPERTIES + = CoreUtils.getProperties("azure-communication-email.properties"); - @Generated private final List pipelinePolicies; + @Generated + private final List pipelinePolicies; - /** Create an instance of the AzureCommunicationEmailServiceImplBuilder. */ + /** + * Create an instance of the AzureCommunicationEmailServiceImplBuilder. + */ @Generated public AzureCommunicationEmailServiceImplBuilder() { this.pipelinePolicies = new ArrayList<>(); @@ -66,9 +71,12 @@ public AzureCommunicationEmailServiceImplBuilder() { /* * The HTTP pipeline to send requests through. */ - @Generated private HttpPipeline pipeline; + @Generated + private HttpPipeline pipeline; - /** {@inheritDoc}. */ + /** + * {@inheritDoc}. + */ @Generated @Override public AzureCommunicationEmailServiceImplBuilder pipeline(HttpPipeline pipeline) { @@ -79,9 +87,12 @@ public AzureCommunicationEmailServiceImplBuilder pipeline(HttpPipeline pipeline) /* * The HTTP client used to send the request. */ - @Generated private HttpClient httpClient; + @Generated + private HttpClient httpClient; - /** {@inheritDoc}. */ + /** + * {@inheritDoc}. + */ @Generated @Override public AzureCommunicationEmailServiceImplBuilder httpClient(HttpClient httpClient) { @@ -92,9 +103,12 @@ public AzureCommunicationEmailServiceImplBuilder httpClient(HttpClient httpClien /* * The logging configuration for HTTP requests and responses. */ - @Generated private HttpLogOptions httpLogOptions; + @Generated + private HttpLogOptions httpLogOptions; - /** {@inheritDoc}. */ + /** + * {@inheritDoc}. + */ @Generated @Override public AzureCommunicationEmailServiceImplBuilder httpLogOptions(HttpLogOptions httpLogOptions) { @@ -105,9 +119,12 @@ public AzureCommunicationEmailServiceImplBuilder httpLogOptions(HttpLogOptions h /* * The client options such as application ID and custom headers to set on a request. */ - @Generated private ClientOptions clientOptions; + @Generated + private ClientOptions clientOptions; - /** {@inheritDoc}. */ + /** + * {@inheritDoc}. + */ @Generated @Override public AzureCommunicationEmailServiceImplBuilder clientOptions(ClientOptions clientOptions) { @@ -118,9 +135,12 @@ public AzureCommunicationEmailServiceImplBuilder clientOptions(ClientOptions cli /* * The retry options to configure retry policy for failed requests. */ - @Generated private RetryOptions retryOptions; + @Generated + private RetryOptions retryOptions; - /** {@inheritDoc}. */ + /** + * {@inheritDoc}. + */ @Generated @Override public AzureCommunicationEmailServiceImplBuilder retryOptions(RetryOptions retryOptions) { @@ -128,7 +148,9 @@ public AzureCommunicationEmailServiceImplBuilder retryOptions(RetryOptions retry return this; } - /** {@inheritDoc}. */ + /** + * {@inheritDoc}. + */ @Generated @Override public AzureCommunicationEmailServiceImplBuilder addPolicy(HttpPipelinePolicy customPolicy) { @@ -140,9 +162,12 @@ public AzureCommunicationEmailServiceImplBuilder addPolicy(HttpPipelinePolicy cu /* * The configuration store that is used during construction of the service client. */ - @Generated private Configuration configuration; + @Generated + private Configuration configuration; - /** {@inheritDoc}. */ + /** + * {@inheritDoc}. + */ @Generated @Override public AzureCommunicationEmailServiceImplBuilder configuration(Configuration configuration) { @@ -153,9 +178,12 @@ public AzureCommunicationEmailServiceImplBuilder configuration(Configuration con /* * The AzureKeyCredential used for authentication. */ - @Generated private AzureKeyCredential azureKeyCredential; + @Generated + private AzureKeyCredential azureKeyCredential; - /** {@inheritDoc}. */ + /** + * {@inheritDoc}. + */ @Generated @Override public AzureCommunicationEmailServiceImplBuilder credential(AzureKeyCredential azureKeyCredential) { @@ -166,9 +194,12 @@ public AzureCommunicationEmailServiceImplBuilder credential(AzureKeyCredential a /* * The service endpoint */ - @Generated private String endpoint; + @Generated + private String endpoint; - /** {@inheritDoc}. */ + /** + * {@inheritDoc}. + */ @Generated @Override public AzureCommunicationEmailServiceImplBuilder endpoint(String endpoint) { @@ -179,11 +210,12 @@ public AzureCommunicationEmailServiceImplBuilder endpoint(String endpoint) { /* * Api Version */ - @Generated private String apiVersion; + @Generated + private String apiVersion; /** * Sets Api Version. - * + * * @param apiVersion the apiVersion value. * @return the AzureCommunicationEmailServiceImplBuilder. */ @@ -196,11 +228,12 @@ public AzureCommunicationEmailServiceImplBuilder apiVersion(String apiVersion) { /* * The serializer to serialize an object into a string */ - @Generated private SerializerAdapter serializerAdapter; + @Generated + private SerializerAdapter serializerAdapter; /** * Sets The serializer to serialize an object into a string. - * + * * @param serializerAdapter the serializerAdapter value. * @return the AzureCommunicationEmailServiceImplBuilder. */ @@ -213,11 +246,12 @@ public AzureCommunicationEmailServiceImplBuilder serializerAdapter(SerializerAda /* * The retry policy that will attempt to retry failed requests, if applicable. */ - @Generated private RetryPolicy retryPolicy; + @Generated + private RetryPolicy retryPolicy; /** * Sets The retry policy that will attempt to retry failed requests, if applicable. - * + * * @param retryPolicy the retryPolicy value. * @return the AzureCommunicationEmailServiceImplBuilder. */ @@ -229,25 +263,32 @@ public AzureCommunicationEmailServiceImplBuilder retryPolicy(RetryPolicy retryPo /** * Builds an instance of AzureCommunicationEmailServiceImpl with the provided parameters. - * + * * @return an instance of AzureCommunicationEmailServiceImpl. */ @Generated public AzureCommunicationEmailServiceImpl buildClient() { + this.validateClient(); HttpPipeline localPipeline = (pipeline != null) ? pipeline : createHttpPipeline(); String localApiVersion = (apiVersion != null) ? apiVersion : "2023-03-31"; - SerializerAdapter localSerializerAdapter = - (serializerAdapter != null) ? serializerAdapter : JacksonAdapter.createDefaultSerializerAdapter(); - AzureCommunicationEmailServiceImpl client = - new AzureCommunicationEmailServiceImpl( - localPipeline, localSerializerAdapter, endpoint, localApiVersion); + SerializerAdapter localSerializerAdapter + = (serializerAdapter != null) ? serializerAdapter : JacksonAdapter.createDefaultSerializerAdapter(); + AzureCommunicationEmailServiceImpl client = new AzureCommunicationEmailServiceImpl(localPipeline, + localSerializerAdapter, this.endpoint, localApiVersion); 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 = - (configuration == null) ? Configuration.getGlobalConfiguration() : configuration; + Configuration buildConfiguration + = (configuration == null) ? Configuration.getGlobalConfiguration() : configuration; HttpLogOptions localHttpLogOptions = this.httpLogOptions == null ? new HttpLogOptions() : this.httpLogOptions; ClientOptions localClientOptions = this.clientOptions == null ? new ClientOptions() : this.clientOptions; List policies = new ArrayList<>(); @@ -257,32 +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(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) - .forEach(p -> policies.add(p)); + .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()); - policies.add(new CookiePolicy()); if (azureKeyCredential != null) { policies.add(new AzureKeyCredentialPolicy("Authorization", azureKeyCredential)); } this.pipelinePolicies.stream() - .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) - .forEach(p -> policies.add(p)); + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) + .forEach(p -> policies.add(p)); HttpPolicyProviders.addAfterRetryPolicies(policies); - policies.add(new HttpLoggingPolicy(httpLogOptions)); - HttpPipeline httpPipeline = - new HttpPipelineBuilder() - .policies(policies.toArray(new HttpPipelinePolicy[0])) - .httpClient(httpClient) - .clientOptions(localClientOptions) - .build(); + policies.add(new HttpLoggingPolicy(localHttpLogOptions)); + HttpPipeline httpPipeline = new HttpPipelineBuilder().policies(policies.toArray(new HttpPipelinePolicy[0])) + .httpClient(httpClient) + .clientOptions(localClientOptions) + .build(); return httpPipeline; } } diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/EmailsImpl.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/EmailsImpl.java index 5fb77249b7685..df2d549ddb87a 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/EmailsImpl.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/EmailsImpl.java @@ -27,17 +27,24 @@ import com.azure.core.util.FluxUtil; import com.azure.core.util.polling.DefaultPollingStrategy; import com.azure.core.util.polling.PollerFlux; +import com.azure.core.util.polling.PollingStrategyOptions; import com.azure.core.util.serializer.TypeReference; import java.time.Duration; import java.util.UUID; import reactor.core.publisher.Mono; -/** An instance of this class provides access to all the operations defined in Emails. */ +/** + * An instance of this class provides access to all the operations defined in Emails. + */ public final class EmailsImpl { - /** The proxy service used to perform REST calls. */ + /** + * The proxy service used to perform REST calls. + */ private final EmailsService service; - /** The service client containing this operation class. */ + /** + * The service client containing this operation class. + */ private final AzureCommunicationEmailServiceImpl client; /** @@ -58,26 +65,19 @@ public final class EmailsImpl { @ServiceInterface(name = "AzureCommunicationEm") public interface EmailsService { @Get("/emails/operations/{operationId}") - @ExpectedResponses({200}) + @ExpectedResponses({ 200 }) @UnexpectedResponseExceptionType(ErrorResponseException.class) - Mono getSendResult( - @HostParam("endpoint") String endpoint, - @PathParam("operationId") String operationId, - @QueryParam("api-version") String apiVersion, - @HeaderParam("Accept") String accept, - Context context); + Mono getSendResult(@HostParam("endpoint") String endpoint, + @PathParam("operationId") String operationId, @QueryParam("api-version") String apiVersion, + @HeaderParam("Accept") String accept, Context context); @Post("/emails:send") - @ExpectedResponses({202}) + @ExpectedResponses({ 202 }) @UnexpectedResponseExceptionType(ErrorResponseException.class) - Mono send( - @HostParam("endpoint") String endpoint, - @HeaderParam("Operation-Id") UUID operationId, - @HeaderParam("x-ms-client-request-id") UUID clientRequestId, - @QueryParam("api-version") String apiVersion, - @BodyParam("application/json") EmailMessage message, - @HeaderParam("Accept") String accept, - Context context); + Mono send(@HostParam("endpoint") String endpoint, + @HeaderParam("Operation-Id") UUID operationId, @HeaderParam("x-ms-client-request-id") UUID clientRequestId, + @QueryParam("api-version") String apiVersion, @BodyParam("application/json") EmailMessage message, + @HeaderParam("Accept") String accept, Context context); } /** @@ -92,10 +92,8 @@ Mono send( @ServiceMethod(returns = ReturnType.SINGLE) public Mono getSendResultWithResponseAsync(String operationId) { final String accept = "application/json"; - return FluxUtil.withContext( - context -> - service.getSendResult( - this.client.getEndpoint(), operationId, this.client.getApiVersion(), accept, context)); + return FluxUtil.withContext(context -> service.getSendResult(this.client.getEndpoint(), operationId, + this.client.getApiVersion(), accept, context)); } /** @@ -111,8 +109,8 @@ public Mono getSendResultWithResponseAsync(String o @ServiceMethod(returns = ReturnType.SINGLE) public Mono getSendResultWithResponseAsync(String operationId, Context context) { final String accept = "application/json"; - return service.getSendResult( - this.client.getEndpoint(), operationId, this.client.getApiVersion(), accept, context); + return service.getSendResult(this.client.getEndpoint(), operationId, this.client.getApiVersion(), accept, + context); } /** @@ -149,7 +147,7 @@ public Mono getSendResultAsync(String operationId, Context cont * * @param message Message payload for sending an email. * @param operationId This is the ID provided by the customer to identify the long running operation. If an ID is - * not provided by the customer, the service will generate one. + * not provided by the customer, the service will generate one. * @param clientRequestId Tracking ID sent with the request to help with debugging. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws ErrorResponseException thrown if the request is rejected by server. @@ -157,19 +155,11 @@ public Mono getSendResultAsync(String operationId, Context cont * @return status of the long running operation on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono sendWithResponseAsync( - EmailMessage message, UUID operationId, UUID clientRequestId) { + public Mono sendWithResponseAsync(EmailMessage message, UUID operationId, + UUID clientRequestId) { final String accept = "application/json"; - return FluxUtil.withContext( - context -> - service.send( - this.client.getEndpoint(), - operationId, - clientRequestId, - this.client.getApiVersion(), - message, - accept, - context)); + return FluxUtil.withContext(context -> service.send(this.client.getEndpoint(), operationId, clientRequestId, + this.client.getApiVersion(), message, accept, context)); } /** @@ -177,7 +167,7 @@ public Mono sendWithResponseAsync( * * @param message Message payload for sending an email. * @param operationId This is the ID provided by the customer to identify the long running operation. If an ID is - * not provided by the customer, the service will generate one. + * not provided by the customer, the service will generate one. * @param clientRequestId Tracking ID sent with the request to help with debugging. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. @@ -186,17 +176,11 @@ public Mono sendWithResponseAsync( * @return status of the long running operation on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono sendWithResponseAsync( - EmailMessage message, UUID operationId, UUID clientRequestId, Context context) { + public Mono sendWithResponseAsync(EmailMessage message, UUID operationId, UUID clientRequestId, + Context context) { final String accept = "application/json"; - return service.send( - this.client.getEndpoint(), - operationId, - clientRequestId, - this.client.getApiVersion(), - message, - accept, - context); + return service.send(this.client.getEndpoint(), operationId, clientRequestId, this.client.getApiVersion(), + message, accept, context); } /** @@ -204,7 +188,7 @@ public Mono sendWithResponseAsync( * * @param message Message payload for sending an email. * @param operationId This is the ID provided by the customer to identify the long running operation. If an ID is - * not provided by the customer, the service will generate one. + * not provided by the customer, the service will generate one. * @param clientRequestId Tracking ID sent with the request to help with debugging. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws ErrorResponseException thrown if the request is rejected by server. @@ -212,18 +196,14 @@ public Mono sendWithResponseAsync( * @return the {@link PollerFlux} for polling of status of the long running operation. */ @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) - public PollerFlux beginSendAsync( - EmailMessage message, UUID operationId, UUID clientRequestId) { - return PollerFlux.create( - Duration.ofSeconds(1), - () -> this.sendWithResponseAsync(message, operationId, clientRequestId), - new DefaultPollingStrategy<>( - this.client.getHttpPipeline(), - "{endpoint}".replace("{endpoint}", this.client.getEndpoint()), - null, - Context.NONE), - TypeReference.createInstance(EmailSendResult.class), - TypeReference.createInstance(EmailSendResult.class)); + public PollerFlux beginSendAsync(EmailMessage message, UUID operationId, + UUID clientRequestId) { + return PollerFlux.create(Duration.ofSeconds(1), + () -> this.sendWithResponseAsync(message, operationId, clientRequestId), + new DefaultPollingStrategy<>(new PollingStrategyOptions(this.client.getHttpPipeline()) + .setEndpoint("{endpoint}".replace("{endpoint}", this.client.getEndpoint())) + .setContext(Context.NONE)), + TypeReference.createInstance(EmailSendResult.class), TypeReference.createInstance(EmailSendResult.class)); } /** @@ -231,7 +211,7 @@ public PollerFlux beginSendAsync( * * @param message Message payload for sending an email. * @param operationId This is the ID provided by the customer to identify the long running operation. If an ID is - * not provided by the customer, the service will generate one. + * not provided by the customer, the service will generate one. * @param clientRequestId Tracking ID sent with the request to help with debugging. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. @@ -240,17 +220,13 @@ public PollerFlux beginSendAsync( * @return the {@link PollerFlux} for polling of status of the long running operation. */ @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) - public PollerFlux beginSendAsync( - EmailMessage message, UUID operationId, UUID clientRequestId, Context context) { - return PollerFlux.create( - Duration.ofSeconds(1), - () -> this.sendWithResponseAsync(message, operationId, clientRequestId, context), - new DefaultPollingStrategy<>( - this.client.getHttpPipeline(), - "{endpoint}".replace("{endpoint}", this.client.getEndpoint()), - null, - context), - TypeReference.createInstance(EmailSendResult.class), - TypeReference.createInstance(EmailSendResult.class)); + public PollerFlux beginSendAsync(EmailMessage message, UUID operationId, + UUID clientRequestId, Context context) { + return PollerFlux.create(Duration.ofSeconds(1), + () -> this.sendWithResponseAsync(message, operationId, clientRequestId, context), + new DefaultPollingStrategy<>(new PollingStrategyOptions(this.client.getHttpPipeline()) + .setEndpoint("{endpoint}".replace("{endpoint}", this.client.getEndpoint())) + .setContext(context)), + TypeReference.createInstance(EmailSendResult.class), TypeReference.createInstance(EmailSendResult.class)); } } diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailAttachment.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailAttachment.java index 3605b97a28be1..d0f32f9e05c84 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailAttachment.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailAttachment.java @@ -5,42 +5,42 @@ package com.azure.communication.email.implementation.models; import com.azure.core.annotation.Immutable; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; -/** Attachment to the email. */ +/** + * Attachment to the email. + */ @Immutable -public final class EmailAttachment { +public final class EmailAttachment implements JsonSerializable { /* * Name of the attachment */ - @JsonProperty(value = "name", required = true) - private String name; + private final String name; /* * MIME type of the content being attached. */ - @JsonProperty(value = "contentType", required = true) - private String contentType; + private final String contentType; /* * Base64 encoded contents of the attachment */ - @JsonProperty(value = "contentInBase64", required = true) - private String contentInBase64; + private final String contentInBase64; /** * Creates an instance of EmailAttachment class. - * + * * @param name the name value to set. * @param contentType the contentType value to set. * @param contentInBase64 the contentInBase64 value to set. */ - @JsonCreator - public EmailAttachment( - @JsonProperty(value = "name", required = true) String name, - @JsonProperty(value = "contentType", required = true) String contentType, - @JsonProperty(value = "contentInBase64", required = true) String contentInBase64) { + public EmailAttachment(String name, String contentType, String contentInBase64) { this.name = name; this.contentType = contentType; this.contentInBase64 = contentInBase64; @@ -48,7 +48,7 @@ public EmailAttachment( /** * Get the name property: Name of the attachment. - * + * * @return the name value. */ public String getName() { @@ -57,7 +57,7 @@ public String getName() { /** * Get the contentType property: MIME type of the content being attached. - * + * * @return the contentType value. */ public String getContentType() { @@ -66,10 +66,75 @@ public String getContentType() { /** * Get the contentInBase64 property: Base64 encoded contents of the attachment. - * + * * @return the contentInBase64 value. */ public String getContentInBase64() { return this.contentInBase64; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("name", this.name); + jsonWriter.writeStringField("contentType", this.contentType); + jsonWriter.writeStringField("contentInBase64", this.contentInBase64); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of EmailAttachment from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of EmailAttachment 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 EmailAttachment. + */ + public static EmailAttachment fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + boolean nameFound = false; + String name = null; + boolean contentTypeFound = false; + String contentType = null; + boolean contentInBase64Found = false; + String contentInBase64 = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("name".equals(fieldName)) { + name = reader.getString(); + nameFound = true; + } else if ("contentType".equals(fieldName)) { + contentType = reader.getString(); + contentTypeFound = true; + } else if ("contentInBase64".equals(fieldName)) { + contentInBase64 = reader.getString(); + contentInBase64Found = true; + } else { + reader.skipChildren(); + } + } + if (nameFound && contentTypeFound && contentInBase64Found) { + return new EmailAttachment(name, contentType, contentInBase64); + } + List missingProperties = new ArrayList<>(); + if (!nameFound) { + missingProperties.add("name"); + } + if (!contentTypeFound) { + missingProperties.add("contentType"); + } + if (!contentInBase64Found) { + missingProperties.add("contentInBase64"); + } + + throw new IllegalStateException( + "Missing required property/properties: " + String.join(", ", missingProperties)); + }); + } } diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailContent.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailContent.java index f53028707afe3..d69b2e257d834 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailContent.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailContent.java @@ -5,43 +5,44 @@ package com.azure.communication.email.implementation.models; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; -/** Content of the email. */ +/** + * Content of the email. + */ @Fluent -public final class EmailContent { +public final class EmailContent implements JsonSerializable { /* * Subject of the email message */ - @JsonProperty(value = "subject", required = true) - private String subject; + private final String subject; /* * Plain text version of the email message. */ - @JsonProperty(value = "plainText") private String plainText; /* * Html version of the email message. */ - @JsonProperty(value = "html") private String html; /** * Creates an instance of EmailContent class. - * + * * @param subject the subject value to set. */ - @JsonCreator - public EmailContent(@JsonProperty(value = "subject", required = true) String subject) { + public EmailContent(String subject) { this.subject = subject; } /** * Get the subject property: Subject of the email message. - * + * * @return the subject value. */ public String getSubject() { @@ -50,7 +51,7 @@ public String getSubject() { /** * Get the plainText property: Plain text version of the email message. - * + * * @return the plainText value. */ public String getPlainText() { @@ -59,7 +60,7 @@ public String getPlainText() { /** * Set the plainText property: Plain text version of the email message. - * + * * @param plainText the plainText value to set. * @return the EmailContent object itself. */ @@ -70,7 +71,7 @@ public EmailContent setPlainText(String plainText) { /** * Get the html property: Html version of the email message. - * + * * @return the html value. */ public String getHtml() { @@ -79,7 +80,7 @@ public String getHtml() { /** * Set the html property: Html version of the email message. - * + * * @param html the html value to set. * @return the EmailContent object itself. */ @@ -87,4 +88,57 @@ public EmailContent setHtml(String html) { this.html = html; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("subject", this.subject); + jsonWriter.writeStringField("plainText", this.plainText); + jsonWriter.writeStringField("html", this.html); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of EmailContent from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of EmailContent 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 EmailContent. + */ + public static EmailContent fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + boolean subjectFound = false; + String subject = null; + String plainText = null; + String html = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("subject".equals(fieldName)) { + subject = reader.getString(); + subjectFound = true; + } else if ("plainText".equals(fieldName)) { + plainText = reader.getString(); + } else if ("html".equals(fieldName)) { + html = reader.getString(); + } else { + reader.skipChildren(); + } + } + if (subjectFound) { + EmailContent deserializedEmailContent = new EmailContent(subject); + deserializedEmailContent.plainText = plainText; + deserializedEmailContent.html = html; + + return deserializedEmailContent; + } + throw new IllegalStateException("Missing required property: subject"); + }); + } } diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailMessage.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailMessage.java index b533c2d01f53d..e0ca6d366b0a7 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailMessage.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailMessage.java @@ -6,70 +6,65 @@ import com.azure.communication.email.models.EmailAddress; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; +import java.util.ArrayList; import java.util.List; import java.util.Map; -/** Message payload for sending an email. */ +/** + * Message payload for sending an email. + */ @Fluent -public final class EmailMessage { +public final class EmailMessage implements JsonSerializable { /* * Custom email headers to be passed. */ - @JsonProperty(value = "headers") private Map headers; /* * Sender email address from a verified domain. */ - @JsonProperty(value = "senderAddress", required = true) - private String senderAddress; + private final String senderAddress; /* * Email content to be sent. */ - @JsonProperty(value = "content", required = true) - private EmailContent content; + private final EmailContent content; /* * Recipients for the email. */ - @JsonProperty(value = "recipients", required = true) - private EmailRecipients recipients; + private final EmailRecipients recipients; /* - * List of attachments. Please note that we limit the total size of an email request (which includes attachments) - * to 10MB. + * List of attachments. Please note that we limit the total size of an email request (which includes attachments) to + * 10MB. */ - @JsonProperty(value = "attachments") private List attachments; /* * Email addresses where recipients' replies will be sent to. */ - @JsonProperty(value = "replyTo") private List replyTo; /* * Indicates whether user engagement tracking should be disabled for this request if the resource-level user * engagement tracking setting was already enabled in the control plane. */ - @JsonProperty(value = "userEngagementTrackingDisabled") private Boolean userEngagementTrackingDisabled; /** * Creates an instance of EmailMessage class. - * + * * @param senderAddress the senderAddress value to set. * @param content the content value to set. * @param recipients the recipients value to set. */ - @JsonCreator - public EmailMessage( - @JsonProperty(value = "senderAddress", required = true) String senderAddress, - @JsonProperty(value = "content", required = true) EmailContent content, - @JsonProperty(value = "recipients", required = true) EmailRecipients recipients) { + public EmailMessage(String senderAddress, EmailContent content, EmailRecipients recipients) { this.senderAddress = senderAddress; this.content = content; this.recipients = recipients; @@ -77,7 +72,7 @@ public EmailMessage( /** * Get the headers property: Custom email headers to be passed. - * + * * @return the headers value. */ public Map getHeaders() { @@ -86,7 +81,7 @@ public Map getHeaders() { /** * Set the headers property: Custom email headers to be passed. - * + * * @param headers the headers value to set. * @return the EmailMessage object itself. */ @@ -97,7 +92,7 @@ public EmailMessage setHeaders(Map headers) { /** * Get the senderAddress property: Sender email address from a verified domain. - * + * * @return the senderAddress value. */ public String getSenderAddress() { @@ -106,7 +101,7 @@ public String getSenderAddress() { /** * Get the content property: Email content to be sent. - * + * * @return the content value. */ public EmailContent getContent() { @@ -115,7 +110,7 @@ public EmailContent getContent() { /** * Get the recipients property: Recipients for the email. - * + * * @return the recipients value. */ public EmailRecipients getRecipients() { @@ -125,7 +120,7 @@ public EmailRecipients getRecipients() { /** * Get the attachments property: List of attachments. Please note that we limit the total size of an email request * (which includes attachments) to 10MB. - * + * * @return the attachments value. */ public List getAttachments() { @@ -135,7 +130,7 @@ public List getAttachments() { /** * Set the attachments property: List of attachments. Please note that we limit the total size of an email request * (which includes attachments) to 10MB. - * + * * @param attachments the attachments value to set. * @return the EmailMessage object itself. */ @@ -146,7 +141,7 @@ public EmailMessage setAttachments(List attachments) { /** * Get the replyTo property: Email addresses where recipients' replies will be sent to. - * + * * @return the replyTo value. */ public List getReplyTo() { @@ -155,7 +150,7 @@ public List getReplyTo() { /** * Set the replyTo property: Email addresses where recipients' replies will be sent to. - * + * * @param replyTo the replyTo value to set. * @return the EmailMessage object itself. */ @@ -167,7 +162,7 @@ public EmailMessage setReplyTo(List replyTo) { /** * Get the userEngagementTrackingDisabled property: Indicates whether user engagement tracking should be disabled * for this request if the resource-level user engagement tracking setting was already enabled in the control plane. - * + * * @return the userEngagementTrackingDisabled value. */ public Boolean isUserEngagementTrackingDisabled() { @@ -177,7 +172,7 @@ public Boolean isUserEngagementTrackingDisabled() { /** * Set the userEngagementTrackingDisabled property: Indicates whether user engagement tracking should be disabled * for this request if the resource-level user engagement tracking setting was already enabled in the control plane. - * + * * @param userEngagementTrackingDisabled the userEngagementTrackingDisabled value to set. * @return the EmailMessage object itself. */ @@ -185,4 +180,91 @@ public EmailMessage setUserEngagementTrackingDisabled(Boolean userEngagementTrac this.userEngagementTrackingDisabled = userEngagementTrackingDisabled; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("senderAddress", this.senderAddress); + jsonWriter.writeJsonField("content", this.content); + jsonWriter.writeJsonField("recipients", this.recipients); + jsonWriter.writeMapField("headers", this.headers, (writer, element) -> writer.writeString(element)); + jsonWriter.writeArrayField("attachments", this.attachments, (writer, element) -> writer.writeJson(element)); + jsonWriter.writeArrayField("replyTo", this.replyTo, (writer, element) -> writer.writeJson(element)); + jsonWriter.writeBooleanField("userEngagementTrackingDisabled", this.userEngagementTrackingDisabled); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of EmailMessage from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of EmailMessage 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 EmailMessage. + */ + public static EmailMessage fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + boolean senderAddressFound = false; + String senderAddress = null; + boolean contentFound = false; + EmailContent content = null; + boolean recipientsFound = false; + EmailRecipients recipients = null; + Map headers = null; + List attachments = null; + List replyTo = null; + Boolean userEngagementTrackingDisabled = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("senderAddress".equals(fieldName)) { + senderAddress = reader.getString(); + senderAddressFound = true; + } else if ("content".equals(fieldName)) { + content = EmailContent.fromJson(reader); + contentFound = true; + } else if ("recipients".equals(fieldName)) { + recipients = EmailRecipients.fromJson(reader); + recipientsFound = true; + } else if ("headers".equals(fieldName)) { + headers = reader.readMap(reader1 -> reader1.getString()); + } else if ("attachments".equals(fieldName)) { + attachments = reader.readArray(reader1 -> EmailAttachment.fromJson(reader1)); + } else if ("replyTo".equals(fieldName)) { + replyTo = reader.readArray(reader1 -> EmailAddress.fromJson(reader1)); + } else if ("userEngagementTrackingDisabled".equals(fieldName)) { + userEngagementTrackingDisabled = reader.getNullable(JsonReader::getBoolean); + } else { + reader.skipChildren(); + } + } + if (senderAddressFound && contentFound && recipientsFound) { + EmailMessage deserializedEmailMessage = new EmailMessage(senderAddress, content, recipients); + deserializedEmailMessage.headers = headers; + deserializedEmailMessage.attachments = attachments; + deserializedEmailMessage.replyTo = replyTo; + deserializedEmailMessage.userEngagementTrackingDisabled = userEngagementTrackingDisabled; + + return deserializedEmailMessage; + } + List missingProperties = new ArrayList<>(); + if (!senderAddressFound) { + missingProperties.add("senderAddress"); + } + if (!contentFound) { + missingProperties.add("content"); + } + if (!recipientsFound) { + missingProperties.add("recipients"); + } + + throw new IllegalStateException( + "Missing required property/properties: " + String.join(", ", missingProperties)); + }); + } } diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailRecipients.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailRecipients.java index 969044048e817..c4ba98a5c9583 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailRecipients.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailRecipients.java @@ -6,36 +6,42 @@ import com.azure.communication.email.models.EmailAddress; 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; -/** Recipients of the email. */ +/** + * Recipients of the email. + */ @Fluent -public final class EmailRecipients { +public final class EmailRecipients implements JsonSerializable { /* * Email To recipients */ - @JsonProperty(value = "to") private List to; /* * Email CC recipients */ - @JsonProperty(value = "cc") private List cc; /* * Email BCC recipients */ - @JsonProperty(value = "bcc") private List bCC; - /** Creates an instance of EmailRecipients class. */ - public EmailRecipients() {} + /** + * Creates an instance of EmailRecipients class. + */ + public EmailRecipients() { + } /** * Get the to property: Email To recipients. - * + * * @return the to value. */ public List getTo() { @@ -44,7 +50,7 @@ public List getTo() { /** * Set the to property: Email To recipients. - * + * * @param to the to value to set. * @return the EmailRecipients object itself. */ @@ -55,7 +61,7 @@ public EmailRecipients setTo(List to) { /** * Get the cc property: Email CC recipients. - * + * * @return the cc value. */ public List getCc() { @@ -64,7 +70,7 @@ public List getCc() { /** * Set the cc property: Email CC recipients. - * + * * @param cc the cc value to set. * @return the EmailRecipients object itself. */ @@ -75,7 +81,7 @@ public EmailRecipients setCc(List cc) { /** * Get the bCC property: Email BCC recipients. - * + * * @return the bCC value. */ public List getBCC() { @@ -84,7 +90,7 @@ public List getBCC() { /** * Set the bCC property: Email BCC recipients. - * + * * @param bCC the bCC value to set. * @return the EmailRecipients object itself. */ @@ -92,4 +98,49 @@ public EmailRecipients setBCC(List bCC) { this.bCC = bCC; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeArrayField("to", this.to, (writer, element) -> writer.writeJson(element)); + jsonWriter.writeArrayField("cc", this.cc, (writer, element) -> writer.writeJson(element)); + jsonWriter.writeArrayField("bcc", this.bCC, (writer, element) -> writer.writeJson(element)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of EmailRecipients from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of EmailRecipients 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 EmailRecipients. + */ + public static EmailRecipients fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + EmailRecipients deserializedEmailRecipients = new EmailRecipients(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("to".equals(fieldName)) { + List to = reader.readArray(reader1 -> EmailAddress.fromJson(reader1)); + deserializedEmailRecipients.to = to; + } else if ("cc".equals(fieldName)) { + List cc = reader.readArray(reader1 -> EmailAddress.fromJson(reader1)); + deserializedEmailRecipients.cc = cc; + } else if ("bcc".equals(fieldName)) { + List bCC = reader.readArray(reader1 -> EmailAddress.fromJson(reader1)); + deserializedEmailRecipients.bCC = bCC; + } else { + reader.skipChildren(); + } + } + + return deserializedEmailRecipients; + }); + } } diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailSendResult.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailSendResult.java index fd4e6345cc6b5..859f6f1963b69 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailSendResult.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailSendResult.java @@ -6,47 +6,48 @@ import com.azure.communication.email.models.EmailSendStatus; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; -/** Status of the long running operation. */ +/** + * Status of the long running operation. + */ @Fluent -public final class EmailSendResult { +public final class EmailSendResult implements JsonSerializable { /* * The unique id of the operation. Use a UUID. */ - @JsonProperty(value = "id", required = true) - private String id; + private final String id; /* * Status of operation. */ - @JsonProperty(value = "status", required = true) - private EmailSendStatus status; + private final EmailSendStatus status; /* * Error details when status is a non-success terminal state. */ - @JsonProperty(value = "error") private ErrorDetail error; /** * Creates an instance of EmailSendResult class. - * + * * @param id the id value to set. * @param status the status value to set. */ - @JsonCreator - public EmailSendResult( - @JsonProperty(value = "id", required = true) String id, - @JsonProperty(value = "status", required = true) EmailSendStatus status) { + public EmailSendResult(String id, EmailSendStatus status) { this.id = id; this.status = status; } /** * Get the id property: The unique id of the operation. Use a UUID. - * + * * @return the id value. */ public String getId() { @@ -55,7 +56,7 @@ public String getId() { /** * Get the status property: Status of operation. - * + * * @return the status value. */ public EmailSendStatus getStatus() { @@ -64,7 +65,7 @@ public EmailSendStatus getStatus() { /** * Get the error property: Error details when status is a non-success terminal state. - * + * * @return the error value. */ public ErrorDetail getError() { @@ -73,7 +74,7 @@ public ErrorDetail getError() { /** * Set the error property: Error details when status is a non-success terminal state. - * + * * @param error the error value to set. * @return the EmailSendResult object itself. */ @@ -81,4 +82,67 @@ public EmailSendResult setError(ErrorDetail error) { this.error = error; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("id", this.id); + jsonWriter.writeStringField("status", this.status == null ? null : this.status.toString()); + jsonWriter.writeJsonField("error", this.error); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of EmailSendResult from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of EmailSendResult 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 EmailSendResult. + */ + public static EmailSendResult fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + boolean idFound = false; + String id = null; + boolean statusFound = false; + EmailSendStatus status = null; + ErrorDetail error = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("id".equals(fieldName)) { + id = reader.getString(); + idFound = true; + } else if ("status".equals(fieldName)) { + status = EmailSendStatus.fromString(reader.getString()); + statusFound = true; + } else if ("error".equals(fieldName)) { + error = ErrorDetail.fromJson(reader); + } else { + reader.skipChildren(); + } + } + if (idFound && statusFound) { + EmailSendResult deserializedEmailSendResult = new EmailSendResult(id, status); + deserializedEmailSendResult.error = error; + + return deserializedEmailSendResult; + } + List missingProperties = new ArrayList<>(); + if (!idFound) { + missingProperties.add("id"); + } + if (!statusFound) { + missingProperties.add("status"); + } + + throw new IllegalStateException( + "Missing required property/properties: " + String.join(", ", missingProperties)); + }); + } } diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailsGetSendResultHeaders.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailsGetSendResultHeaders.java index 95d8f17a63a10..fc54dd404f69d 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailsGetSendResultHeaders.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailsGetSendResultHeaders.java @@ -7,21 +7,21 @@ import com.azure.core.annotation.Fluent; import com.azure.core.http.HttpHeaderName; import com.azure.core.http.HttpHeaders; -import com.fasterxml.jackson.annotation.JsonProperty; -/** The EmailsGetSendResultHeaders model. */ +/** + * The EmailsGetSendResultHeaders model. + */ @Fluent public final class EmailsGetSendResultHeaders { /* * The retry-after property. */ - @JsonProperty(value = "retry-after") private Integer retryAfter; // HttpHeaders containing the raw property values. /** * Creates an instance of EmailsGetSendResultHeaders class. - * + * * @param rawHeaders The raw HttpHeaders that will be used to create the property values. */ public EmailsGetSendResultHeaders(HttpHeaders rawHeaders) { @@ -33,7 +33,7 @@ public EmailsGetSendResultHeaders(HttpHeaders rawHeaders) { /** * Get the retryAfter property: The retry-after property. - * + * * @return the retryAfter value. */ public Integer getRetryAfter() { @@ -42,7 +42,7 @@ public Integer getRetryAfter() { /** * Set the retryAfter property: The retry-after property. - * + * * @param retryAfter the retryAfter value to set. * @return the EmailsGetSendResultHeaders object itself. */ diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailsGetSendResultResponse.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailsGetSendResultResponse.java index 5df9aeceec633..e10b365975ad5 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailsGetSendResultResponse.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailsGetSendResultResponse.java @@ -8,29 +8,27 @@ import com.azure.core.http.HttpRequest; import com.azure.core.http.rest.ResponseBase; -/** Contains all response data for the getSendResult operation. */ +/** + * Contains all response data for the getSendResult operation. + */ public final class EmailsGetSendResultResponse extends ResponseBase { /** * Creates an instance of EmailsGetSendResultResponse. - * + * * @param request the request which resulted in this EmailsGetSendResultResponse. * @param statusCode the status code of the HTTP response. * @param rawHeaders the raw headers of the HTTP response. * @param value the deserialized value of the HTTP response. * @param headers the deserialized headers of the HTTP response. */ - public EmailsGetSendResultResponse( - HttpRequest request, - int statusCode, - HttpHeaders rawHeaders, - EmailSendResult value, - EmailsGetSendResultHeaders headers) { + public EmailsGetSendResultResponse(HttpRequest request, int statusCode, HttpHeaders rawHeaders, + EmailSendResult value, EmailsGetSendResultHeaders headers) { super(request, statusCode, rawHeaders, value, headers); } /** * Gets the deserialized response body. - * + * * @return the deserialized response body. */ @Override diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailsSendHeaders.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailsSendHeaders.java index debca7bd6100f..19652a4ec9af2 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailsSendHeaders.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailsSendHeaders.java @@ -7,21 +7,20 @@ import com.azure.core.annotation.Fluent; import com.azure.core.http.HttpHeaderName; import com.azure.core.http.HttpHeaders; -import com.fasterxml.jackson.annotation.JsonProperty; -/** The EmailsSendHeaders model. */ +/** + * The EmailsSendHeaders model. + */ @Fluent public final class EmailsSendHeaders { /* * The retry-after property. */ - @JsonProperty(value = "retry-after") private Integer retryAfter; /* * The Operation-Location property. */ - @JsonProperty(value = "Operation-Location") private String operationLocation; private static final HttpHeaderName OPERATION_LOCATION = HttpHeaderName.fromString("Operation-Location"); @@ -29,7 +28,7 @@ public final class EmailsSendHeaders { // HttpHeaders containing the raw property values. /** * Creates an instance of EmailsSendHeaders class. - * + * * @param rawHeaders The raw HttpHeaders that will be used to create the property values. */ public EmailsSendHeaders(HttpHeaders rawHeaders) { @@ -42,7 +41,7 @@ public EmailsSendHeaders(HttpHeaders rawHeaders) { /** * Get the retryAfter property: The retry-after property. - * + * * @return the retryAfter value. */ public Integer getRetryAfter() { @@ -51,7 +50,7 @@ public Integer getRetryAfter() { /** * Set the retryAfter property: The retry-after property. - * + * * @param retryAfter the retryAfter value to set. * @return the EmailsSendHeaders object itself. */ @@ -62,7 +61,7 @@ public EmailsSendHeaders setRetryAfter(Integer retryAfter) { /** * Get the operationLocation property: The Operation-Location property. - * + * * @return the operationLocation value. */ public String getOperationLocation() { @@ -71,7 +70,7 @@ public String getOperationLocation() { /** * Set the operationLocation property: The Operation-Location property. - * + * * @param operationLocation the operationLocation value to set. * @return the EmailsSendHeaders object itself. */ diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailsSendResponse.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailsSendResponse.java index fd3bb3aeb983f..c883d4be54054 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailsSendResponse.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailsSendResponse.java @@ -8,29 +8,27 @@ import com.azure.core.http.HttpRequest; import com.azure.core.http.rest.ResponseBase; -/** Contains all response data for the send operation. */ +/** + * Contains all response data for the send operation. + */ public final class EmailsSendResponse extends ResponseBase { /** * Creates an instance of EmailsSendResponse. - * + * * @param request the request which resulted in this EmailsSendResponse. * @param statusCode the status code of the HTTP response. * @param rawHeaders the raw headers of the HTTP response. * @param value the deserialized value of the HTTP response. * @param headers the deserialized headers of the HTTP response. */ - public EmailsSendResponse( - HttpRequest request, - int statusCode, - HttpHeaders rawHeaders, - EmailSendResult value, - EmailsSendHeaders headers) { + public EmailsSendResponse(HttpRequest request, int statusCode, HttpHeaders rawHeaders, EmailSendResult value, + EmailsSendHeaders headers) { super(request, statusCode, rawHeaders, value, headers); } /** * Gets the deserialized response body. - * + * * @return the deserialized response body. */ @Override diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/ErrorAdditionalInfo.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/ErrorAdditionalInfo.java index e0c4aaf588ee0..e78dfb755ae96 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/ErrorAdditionalInfo.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/ErrorAdditionalInfo.java @@ -5,29 +5,36 @@ package com.azure.communication.email.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 resource management error additional info. */ +/** + * The resource management error additional info. + */ @Immutable -public final class ErrorAdditionalInfo { +public final class ErrorAdditionalInfo implements JsonSerializable { /* * The additional info type. */ - @JsonProperty(value = "type", access = JsonProperty.Access.WRITE_ONLY) private String type; /* * The additional info. */ - @JsonProperty(value = "info", access = JsonProperty.Access.WRITE_ONLY) private Object info; - /** Creates an instance of ErrorAdditionalInfo class. */ - public ErrorAdditionalInfo() {} + /** + * Creates an instance of ErrorAdditionalInfo class. + */ + public ErrorAdditionalInfo() { + } /** * Get the type property: The additional info type. - * + * * @return the type value. */ public String getType() { @@ -36,10 +43,47 @@ public String getType() { /** * Get the info property: The additional info. - * + * * @return the info value. */ public Object getInfo() { return this.info; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ErrorAdditionalInfo from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ErrorAdditionalInfo 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 ErrorAdditionalInfo. + */ + public static ErrorAdditionalInfo fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ErrorAdditionalInfo deserializedErrorAdditionalInfo = new ErrorAdditionalInfo(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("type".equals(fieldName)) { + deserializedErrorAdditionalInfo.type = reader.getString(); + } else if ("info".equals(fieldName)) { + deserializedErrorAdditionalInfo.info = reader.readUntyped(); + } else { + reader.skipChildren(); + } + } + + return deserializedErrorAdditionalInfo; + }); + } } diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/ErrorDetail.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/ErrorDetail.java index 025cfafcb7c05..217e1c99ba2e3 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/ErrorDetail.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/ErrorDetail.java @@ -5,48 +5,52 @@ package com.azure.communication.email.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 error detail. */ +/** + * The error detail. + */ @Immutable -public final class ErrorDetail { +public final class ErrorDetail implements JsonSerializable { /* * The error code. */ - @JsonProperty(value = "code", access = JsonProperty.Access.WRITE_ONLY) private String code; /* * The error message. */ - @JsonProperty(value = "message", access = JsonProperty.Access.WRITE_ONLY) private String message; /* * The error target. */ - @JsonProperty(value = "target", access = JsonProperty.Access.WRITE_ONLY) private String target; /* * The error details. */ - @JsonProperty(value = "details", access = JsonProperty.Access.WRITE_ONLY) private List details; /* * The error additional info. */ - @JsonProperty(value = "additionalInfo", access = JsonProperty.Access.WRITE_ONLY) private List additionalInfo; - /** Creates an instance of ErrorDetail class. */ - public ErrorDetail() {} + /** + * Creates an instance of ErrorDetail class. + */ + public ErrorDetail() { + } /** * Get the code property: The error code. - * + * * @return the code value. */ public String getCode() { @@ -55,7 +59,7 @@ public String getCode() { /** * Get the message property: The error message. - * + * * @return the message value. */ public String getMessage() { @@ -64,7 +68,7 @@ public String getMessage() { /** * Get the target property: The error target. - * + * * @return the target value. */ public String getTarget() { @@ -73,7 +77,7 @@ public String getTarget() { /** * Get the details property: The error details. - * + * * @return the details value. */ public List getDetails() { @@ -82,10 +86,56 @@ public List getDetails() { /** * Get the additionalInfo property: The error additional info. - * + * * @return the additionalInfo value. */ public List getAdditionalInfo() { return this.additionalInfo; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ErrorDetail from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ErrorDetail 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 ErrorDetail. + */ + public static ErrorDetail fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ErrorDetail deserializedErrorDetail = new ErrorDetail(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("code".equals(fieldName)) { + deserializedErrorDetail.code = reader.getString(); + } else if ("message".equals(fieldName)) { + deserializedErrorDetail.message = reader.getString(); + } else if ("target".equals(fieldName)) { + deserializedErrorDetail.target = reader.getString(); + } else if ("details".equals(fieldName)) { + List details = reader.readArray(reader1 -> ErrorDetail.fromJson(reader1)); + deserializedErrorDetail.details = details; + } else if ("additionalInfo".equals(fieldName)) { + List additionalInfo + = reader.readArray(reader1 -> ErrorAdditionalInfo.fromJson(reader1)); + deserializedErrorDetail.additionalInfo = additionalInfo; + } else { + reader.skipChildren(); + } + } + + return deserializedErrorDetail; + }); + } } diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/ErrorResponse.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/ErrorResponse.java index 7261524c79657..ce2e72e7bc655 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/ErrorResponse.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/ErrorResponse.java @@ -5,28 +5,34 @@ package com.azure.communication.email.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; /** * Error response - * - *

Common error response for all Azure Resource Manager APIs to return error details for failed operations. (This - * also follows the OData error response format.). + * + * Common error response for all Azure Resource Manager APIs to return error details for failed operations. (This also + * follows the OData error response format.). */ @Fluent -public final class ErrorResponse { +public final class ErrorResponse implements JsonSerializable { /* * The error object. */ - @JsonProperty(value = "error") private ErrorDetail error; - /** Creates an instance of ErrorResponse class. */ - public ErrorResponse() {} + /** + * Creates an instance of ErrorResponse class. + */ + public ErrorResponse() { + } /** * Get the error property: The error object. - * + * * @return the error value. */ public ErrorDetail getError() { @@ -35,7 +41,7 @@ public ErrorDetail getError() { /** * Set the error property: The error object. - * + * * @param error the error value to set. * @return the ErrorResponse object itself. */ @@ -43,4 +49,40 @@ public ErrorResponse setError(ErrorDetail 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 ErrorResponse from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ErrorResponse 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 ErrorResponse. + */ + public static ErrorResponse fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ErrorResponse deserializedErrorResponse = new ErrorResponse(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("error".equals(fieldName)) { + deserializedErrorResponse.error = ErrorDetail.fromJson(reader); + } else { + reader.skipChildren(); + } + } + + return deserializedErrorResponse; + }); + } } diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/ErrorResponseException.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/ErrorResponseException.java index 8c1a3783fe502..94df32a6eae84 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/ErrorResponseException.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/ErrorResponseException.java @@ -7,11 +7,13 @@ import com.azure.core.exception.HttpResponseException; import com.azure.core.http.HttpResponse; -/** Exception thrown for an invalid response with ErrorResponse information. */ +/** + * Exception thrown for an invalid response with ErrorResponse information. + */ public final class ErrorResponseException extends HttpResponseException { /** * Initializes a new instance of the ErrorResponseException class. - * + * * @param message the exception message or the response content if a message is not available. * @param response the HTTP response. */ @@ -21,7 +23,7 @@ public ErrorResponseException(String message, HttpResponse response) { /** * Initializes a new instance of the ErrorResponseException class. - * + * * @param message the exception message or the response content if a message is not available. * @param response the HTTP response. * @param value the deserialized response value. @@ -30,7 +32,9 @@ public ErrorResponseException(String message, HttpResponse response, ErrorRespon super(message, response, value); } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ @Override public ErrorResponse getValue() { return (ErrorResponse) super.getValue(); diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/package-info.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/package-info.java index adfba6254cf48..2f03936cfbef9 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/package-info.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/package-info.java @@ -2,5 +2,8 @@ // Licensed under the MIT License. // Code generated by Microsoft (R) AutoRest Code Generator. -/** Package containing the data models for AzureCommunicationEmailService. Azure Communication Email Service. */ +/** + * Package containing the data models for AzureCommunicationEmailService. + * Azure Communication Email Service. + */ package com.azure.communication.email.implementation.models; diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/package-info.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/package-info.java index cae84a3b9dc0f..7bd9c2d432ef8 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/package-info.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/package-info.java @@ -2,5 +2,8 @@ // Licensed under the MIT License. // Code generated by Microsoft (R) AutoRest Code Generator. -/** Package containing the implementations for AzureCommunicationEmailService. Azure Communication Email Service. */ +/** + * Package containing the implementations for AzureCommunicationEmailService. + * Azure Communication Email Service. + */ package com.azure.communication.email.implementation; diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailAddress.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailAddress.java index 9f2e70e371065..4df9a000bb018 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailAddress.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailAddress.java @@ -5,37 +5,39 @@ package com.azure.communication.email.models; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; -/** An object representing the email address and its display name. */ +/** + * An object representing the email address and its display name. + */ @Fluent -public final class EmailAddress { +public final class EmailAddress implements JsonSerializable { /* * Email address. */ - @JsonProperty(value = "address", required = true) - private String address; + private final String address; /* * Email display name. */ - @JsonProperty(value = "displayName") private String displayName; /** * Creates an instance of EmailAddress class. - * + * * @param address the address value to set. */ - @JsonCreator - public EmailAddress(@JsonProperty(value = "address", required = true) String address) { + public EmailAddress(String address) { this.address = address; } /** * Get the address property: Email address. - * + * * @return the address value. */ public String getAddress() { @@ -44,7 +46,7 @@ public String getAddress() { /** * Get the displayName property: Email display name. - * + * * @return the displayName value. */ public String getDisplayName() { @@ -53,7 +55,7 @@ public String getDisplayName() { /** * Set the displayName property: Email display name. - * + * * @param displayName the displayName value to set. * @return the EmailAddress object itself. */ @@ -61,4 +63,52 @@ public EmailAddress setDisplayName(String displayName) { this.displayName = displayName; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("address", this.address); + jsonWriter.writeStringField("displayName", this.displayName); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of EmailAddress from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of EmailAddress 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 EmailAddress. + */ + public static EmailAddress fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + boolean addressFound = false; + String address = null; + String displayName = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("address".equals(fieldName)) { + address = reader.getString(); + addressFound = true; + } else if ("displayName".equals(fieldName)) { + displayName = reader.getString(); + } else { + reader.skipChildren(); + } + } + if (addressFound) { + EmailAddress deserializedEmailAddress = new EmailAddress(address); + deserializedEmailAddress.displayName = displayName; + + return deserializedEmailAddress; + } + throw new IllegalStateException("Missing required property: address"); + }); + } } diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailSendResult.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailSendResult.java index a01855bac6486..923569b738dbd 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailSendResult.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailSendResult.java @@ -5,28 +5,29 @@ import com.azure.core.annotation.Fluent; import com.azure.core.models.ResponseError; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; + +import java.io.IOException; /** Status of the long running operation. */ @Fluent -public final class EmailSendResult { +public final class EmailSendResult implements JsonSerializable { /* * The unique id of the operation. Use a UUID. */ - @JsonProperty(value = "id", required = true) private String id; /* * Status of operation. */ - @JsonProperty(value = "status", required = true) private EmailSendStatus status; /* * Response error when status is a non-success terminal state. */ - @JsonProperty(value = "error") private ResponseError error; /** @@ -36,11 +37,7 @@ public final class EmailSendResult { * @param status the status value to set. * @param error the error value to set. */ - @JsonCreator - public EmailSendResult( - @JsonProperty(value = "id", required = true) String id, - @JsonProperty(value = "status", required = true) EmailSendStatus status, - @JsonProperty(value = "error") ResponseError error) { + public EmailSendResult(String id, EmailSendStatus status, ResponseError error) { this.id = id; this.status = status; this.error = error; @@ -72,4 +69,46 @@ public EmailSendStatus getStatus() { public ResponseError getError() { return this.error; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("id", id); + jsonWriter.writeStringField("status", status != null ? status.toString() : null); + jsonWriter.writeJsonField("error", error); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of EmailSendResult from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of EmailSendResult 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 EmailSendResult. + */ + public static EmailSendResult fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + String id = null; + EmailSendStatus status = null; + ResponseError error = null; + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("id".equals(fieldName)) { + id = reader.getString(); + } else if ("status".equals(fieldName)) { + status = EmailSendStatus.fromString(reader.getString()); + } else if ("error".equals(fieldName)) { + error = ResponseError.fromJson(reader); + } else { + reader.skipChildren(); + } + } + return new EmailSendResult(id, status, error); + }); + } } diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailSendStatus.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailSendStatus.java index d493f78e49c68..6d189cbab66f0 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailSendStatus.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailSendStatus.java @@ -5,48 +5,59 @@ package com.azure.communication.email.models; import com.azure.core.util.ExpandableStringEnum; -import com.fasterxml.jackson.annotation.JsonCreator; import java.util.Collection; -/** Status of operation. */ +/** + * Status of operation. + */ public final class EmailSendStatus extends ExpandableStringEnum { - /** Static value NotStarted for EmailSendStatus. */ + /** + * Static value NotStarted for EmailSendStatus. + */ public static final EmailSendStatus NOT_STARTED = fromString("NotStarted"); - /** Static value Running for EmailSendStatus. */ + /** + * Static value Running for EmailSendStatus. + */ public static final EmailSendStatus RUNNING = fromString("Running"); - /** Static value Succeeded for EmailSendStatus. */ + /** + * Static value Succeeded for EmailSendStatus. + */ public static final EmailSendStatus SUCCEEDED = fromString("Succeeded"); - /** Static value Failed for EmailSendStatus. */ + /** + * Static value Failed for EmailSendStatus. + */ public static final EmailSendStatus FAILED = fromString("Failed"); - /** Static value Canceled for EmailSendStatus. */ + /** + * Static value Canceled for EmailSendStatus. + */ public static final EmailSendStatus CANCELED = fromString("Canceled"); /** * Creates a new instance of EmailSendStatus value. - * + * * @deprecated Use the {@link #fromString(String)} factory method. */ @Deprecated - public EmailSendStatus() {} + public EmailSendStatus() { + } /** * Creates or finds a EmailSendStatus from its string representation. - * + * * @param name a name to look for. * @return the corresponding EmailSendStatus. */ - @JsonCreator public static EmailSendStatus fromString(String name) { return fromString(name, EmailSendStatus.class); } /** * Gets known EmailSendStatus values. - * + * * @return known EmailSendStatus values. */ public static Collection values() { diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/package-info.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/package-info.java index da60f1282fcb3..ddc04bcb06c6e 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/package-info.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/package-info.java @@ -2,5 +2,8 @@ // Licensed under the MIT License. // Code generated by Microsoft (R) AutoRest Code Generator. -/** Package containing the data models for AzureCommunicationEmailService. Azure Communication Email Service. */ +/** + * Package containing the data models for AzureCommunicationEmailService. + * Azure Communication Email Service. + */ package com.azure.communication.email.models; diff --git a/sdk/communication/azure-communication-email/swagger/README.md b/sdk/communication/azure-communication-email/swagger/README.md index 1a182fefdca71..24c8f181323b9 100644 --- a/sdk/communication/azure-communication-email/swagger/README.md +++ b/sdk/communication/azure-communication-email/swagger/README.md @@ -7,7 +7,7 @@ license-header: MICROSOFT_MIT_SMALL title: Azure Communication Email Service java: true use-extension: - "@autorest/java": "4.1.14" + "@autorest/java": "4.1.33" artifact-id: azure-communication-email namespace: com.azure.communication.email models-subpackage: implementation.models