diff --git a/javagen/src/main/java/com/azure/autorest/template/StreamSerializationModelTemplate.java b/javagen/src/main/java/com/azure/autorest/template/StreamSerializationModelTemplate.java
index 36f7bdacd3..82922d086b 100644
--- a/javagen/src/main/java/com/azure/autorest/template/StreamSerializationModelTemplate.java
+++ b/javagen/src/main/java/com/azure/autorest/template/StreamSerializationModelTemplate.java
@@ -1851,8 +1851,12 @@ private static void handleSettingDeserializedValue(JavaBlock methodBlock, String
// If the property is defined in a super class use the setter as this will be able to set the value in the
// super class.
if (fromSuper
- // If the property is flattened or read-only from parent, it will be shadowed in child class.
- && (!ClientModelUtil.readOnlyNotInCtor(model, property, JavaSettings.getInstance()) && !property.getClientFlatten())) {
+ // If the property is flattened or read-only from parent, and not all models in the inheritance hierarchy are
+ // in the same package, it will be shadowed in child class.
+ && (
+ model.isAllPolymorphicModelsInSamePackage()
+ || (!ClientModelUtil.readOnlyNotInCtor(model, property, JavaSettings.getInstance()) &&
+ !property.getClientFlatten()))) {
if (polymorphicJsonMergePatchScenario) {
// Polymorphic JSON merge patch needs special handling as the setter methods are used to track whether
// the property is included in patch serialization. To prevent deserialization from requiring parent
diff --git a/typespec-tests/src/main/java/com/cadl/streamstyleserialization/StreamStyleSerializationAsyncClient.java b/typespec-tests/src/main/java/com/cadl/streamstyleserialization/StreamStyleSerializationAsyncClient.java
new file mode 100644
index 0000000000..e50e3d1683
--- /dev/null
+++ b/typespec-tests/src/main/java/com/cadl/streamstyleserialization/StreamStyleSerializationAsyncClient.java
@@ -0,0 +1,97 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+// Code generated by Microsoft (R) TypeSpec Code Generator.
+
+package com.cadl.streamstyleserialization;
+
+import com.azure.core.annotation.Generated;
+import com.azure.core.annotation.ReturnType;
+import com.azure.core.annotation.ServiceClient;
+import com.azure.core.annotation.ServiceMethod;
+import com.azure.core.exception.ClientAuthenticationException;
+import com.azure.core.exception.HttpResponseException;
+import com.azure.core.exception.ResourceModifiedException;
+import com.azure.core.exception.ResourceNotFoundException;
+import com.azure.core.http.rest.PagedFlux;
+import com.azure.core.http.rest.PagedResponse;
+import com.azure.core.http.rest.PagedResponseBase;
+import com.azure.core.http.rest.RequestOptions;
+import com.azure.core.util.BinaryData;
+import com.cadl.streamstyleserialization.implementation.AssetsImpl;
+import com.cadl.streamstyleserialization.models.AssetResource;
+import java.util.stream.Collectors;
+import reactor.core.publisher.Flux;
+
+/**
+ * Initializes a new instance of the asynchronous StreamStyleSerializationClient type.
+ */
+@ServiceClient(builder = StreamStyleSerializationClientBuilder.class, isAsync = true)
+public final class StreamStyleSerializationAsyncClient {
+ @Generated
+ private final AssetsImpl serviceClient;
+
+ /**
+ * Initializes an instance of StreamStyleSerializationAsyncClient class.
+ *
+ * @param serviceClient the service client implementation.
+ */
+ @Generated
+ StreamStyleSerializationAsyncClient(AssetsImpl serviceClient) {
+ this.serviceClient = serviceClient;
+ }
+
+ /**
+ * Retrieve a list of assets for the provided search parameters.
+ *
Response Body Schema
+ *
+ * {@code
+ * {
+ * kind: String (Required)
+ * id: String (Required)
+ * name: String (Optional)
+ * }
+ * }
+ *
+ * @param requestOptions The options to configure the HTTP request before HTTP client sends it.
+ * @throws HttpResponseException thrown if the request is rejected by server.
+ * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
+ * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
+ * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
+ * @return paged collection of AssetResource items as paginated response with {@link PagedFlux}.
+ */
+ @Generated
+ @ServiceMethod(returns = ReturnType.COLLECTION)
+ public PagedFlux listAssetResource(RequestOptions requestOptions) {
+ return this.serviceClient.listAssetResourceAsync(requestOptions);
+ }
+
+ /**
+ * Retrieve a list of assets for the provided search parameters.
+ *
+ * @throws HttpResponseException thrown if the request is rejected by server.
+ * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
+ * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
+ * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
+ * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
+ * @return paged collection of AssetResource items as paginated response with {@link PagedFlux}.
+ */
+ @Generated
+ @ServiceMethod(returns = ReturnType.COLLECTION)
+ public PagedFlux listAssetResource() {
+ // Generated convenience method for listAssetResource
+ RequestOptions requestOptions = new RequestOptions();
+ PagedFlux pagedFluxResponse = listAssetResource(requestOptions);
+ return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> {
+ Flux> flux = (continuationTokenParam == null)
+ ? pagedFluxResponse.byPage().take(1)
+ : pagedFluxResponse.byPage(continuationTokenParam).take(1);
+ return flux.map(pagedResponse -> new PagedResponseBase(pagedResponse.getRequest(),
+ pagedResponse.getStatusCode(), pagedResponse.getHeaders(),
+ pagedResponse.getValue()
+ .stream()
+ .map(protocolMethodData -> protocolMethodData.toObject(AssetResource.class))
+ .collect(Collectors.toList()),
+ pagedResponse.getContinuationToken(), null));
+ });
+ }
+}
diff --git a/typespec-tests/src/main/java/com/cadl/streamstyleserialization/StreamStyleSerializationClient.java b/typespec-tests/src/main/java/com/cadl/streamstyleserialization/StreamStyleSerializationClient.java
new file mode 100644
index 0000000000..0a2a742f78
--- /dev/null
+++ b/typespec-tests/src/main/java/com/cadl/streamstyleserialization/StreamStyleSerializationClient.java
@@ -0,0 +1,82 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+// Code generated by Microsoft (R) TypeSpec Code Generator.
+
+package com.cadl.streamstyleserialization;
+
+import com.azure.core.annotation.Generated;
+import com.azure.core.annotation.ReturnType;
+import com.azure.core.annotation.ServiceClient;
+import com.azure.core.annotation.ServiceMethod;
+import com.azure.core.exception.ClientAuthenticationException;
+import com.azure.core.exception.HttpResponseException;
+import com.azure.core.exception.ResourceModifiedException;
+import com.azure.core.exception.ResourceNotFoundException;
+import com.azure.core.http.rest.PagedIterable;
+import com.azure.core.http.rest.RequestOptions;
+import com.azure.core.util.BinaryData;
+import com.cadl.streamstyleserialization.implementation.AssetsImpl;
+import com.cadl.streamstyleserialization.models.AssetResource;
+
+/**
+ * Initializes a new instance of the synchronous StreamStyleSerializationClient type.
+ */
+@ServiceClient(builder = StreamStyleSerializationClientBuilder.class)
+public final class StreamStyleSerializationClient {
+ @Generated
+ private final AssetsImpl serviceClient;
+
+ /**
+ * Initializes an instance of StreamStyleSerializationClient class.
+ *
+ * @param serviceClient the service client implementation.
+ */
+ @Generated
+ StreamStyleSerializationClient(AssetsImpl serviceClient) {
+ this.serviceClient = serviceClient;
+ }
+
+ /**
+ * Retrieve a list of assets for the provided search parameters.
+ * Response Body Schema
+ *
+ * {@code
+ * {
+ * kind: String (Required)
+ * id: String (Required)
+ * name: String (Optional)
+ * }
+ * }
+ *
+ * @param requestOptions The options to configure the HTTP request before HTTP client sends it.
+ * @throws HttpResponseException thrown if the request is rejected by server.
+ * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
+ * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
+ * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
+ * @return paged collection of AssetResource items as paginated response with {@link PagedIterable}.
+ */
+ @Generated
+ @ServiceMethod(returns = ReturnType.COLLECTION)
+ public PagedIterable listAssetResource(RequestOptions requestOptions) {
+ return this.serviceClient.listAssetResource(requestOptions);
+ }
+
+ /**
+ * Retrieve a list of assets for the provided search parameters.
+ *
+ * @throws HttpResponseException thrown if the request is rejected by server.
+ * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
+ * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
+ * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
+ * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
+ * @return paged collection of AssetResource items as paginated response with {@link PagedIterable}.
+ */
+ @Generated
+ @ServiceMethod(returns = ReturnType.COLLECTION)
+ public PagedIterable listAssetResource() {
+ // Generated convenience method for listAssetResource
+ RequestOptions requestOptions = new RequestOptions();
+ return serviceClient.listAssetResource(requestOptions)
+ .mapPage(bodyItemValue -> bodyItemValue.toObject(AssetResource.class));
+ }
+}
diff --git a/typespec-tests/src/main/java/com/cadl/streamstyleserialization/StreamStyleSerializationClientBuilder.java b/typespec-tests/src/main/java/com/cadl/streamstyleserialization/StreamStyleSerializationClientBuilder.java
new file mode 100644
index 0000000000..27e2576183
--- /dev/null
+++ b/typespec-tests/src/main/java/com/cadl/streamstyleserialization/StreamStyleSerializationClientBuilder.java
@@ -0,0 +1,309 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+// Code generated by Microsoft (R) TypeSpec Code Generator.
+
+package com.cadl.streamstyleserialization;
+
+import com.azure.core.annotation.Generated;
+import com.azure.core.annotation.ServiceClientBuilder;
+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.http.HttpClient;
+import com.azure.core.http.HttpHeaders;
+import com.azure.core.http.HttpPipeline;
+import com.azure.core.http.HttpPipelineBuilder;
+import com.azure.core.http.HttpPipelinePosition;
+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.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;
+import com.azure.core.http.policy.RetryOptions;
+import com.azure.core.http.policy.RetryPolicy;
+import com.azure.core.http.policy.UserAgentPolicy;
+import com.azure.core.util.ClientOptions;
+import com.azure.core.util.Configuration;
+import com.azure.core.util.CoreUtils;
+import com.azure.core.util.builder.ClientBuilderUtil;
+import com.azure.core.util.logging.ClientLogger;
+import com.azure.core.util.serializer.JacksonAdapter;
+import com.cadl.streamstyleserialization.implementation.StreamStyleSerializationClientImpl;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * A builder for creating a new instance of the StreamStyleSerializationClient type.
+ */
+@ServiceClientBuilder(
+ serviceClients = { StreamStyleSerializationClient.class, StreamStyleSerializationAsyncClient.class })
+public final class StreamStyleSerializationClientBuilder implements HttpTrait,
+ ConfigurationTrait, EndpointTrait {
+ @Generated
+ private static final String SDK_NAME = "name";
+
+ @Generated
+ private static final String SDK_VERSION = "version";
+
+ @Generated
+ private static final Map PROPERTIES
+ = CoreUtils.getProperties("cadl-streamstyleserialization.properties");
+
+ @Generated
+ private final List pipelinePolicies;
+
+ /**
+ * Create an instance of the StreamStyleSerializationClientBuilder.
+ */
+ @Generated
+ public StreamStyleSerializationClientBuilder() {
+ this.pipelinePolicies = new ArrayList<>();
+ }
+
+ /*
+ * The HTTP pipeline to send requests through.
+ */
+ @Generated
+ private HttpPipeline pipeline;
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Generated
+ @Override
+ public StreamStyleSerializationClientBuilder pipeline(HttpPipeline pipeline) {
+ if (this.pipeline != null && pipeline == null) {
+ LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
+ }
+ this.pipeline = pipeline;
+ return this;
+ }
+
+ /*
+ * The HTTP client used to send the request.
+ */
+ @Generated
+ private HttpClient httpClient;
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Generated
+ @Override
+ public StreamStyleSerializationClientBuilder httpClient(HttpClient httpClient) {
+ this.httpClient = httpClient;
+ return this;
+ }
+
+ /*
+ * The logging configuration for HTTP requests and responses.
+ */
+ @Generated
+ private HttpLogOptions httpLogOptions;
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Generated
+ @Override
+ public StreamStyleSerializationClientBuilder httpLogOptions(HttpLogOptions httpLogOptions) {
+ this.httpLogOptions = httpLogOptions;
+ return this;
+ }
+
+ /*
+ * The client options such as application ID and custom headers to set on a request.
+ */
+ @Generated
+ private ClientOptions clientOptions;
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Generated
+ @Override
+ public StreamStyleSerializationClientBuilder clientOptions(ClientOptions clientOptions) {
+ this.clientOptions = clientOptions;
+ return this;
+ }
+
+ /*
+ * The retry options to configure retry policy for failed requests.
+ */
+ @Generated
+ private RetryOptions retryOptions;
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Generated
+ @Override
+ public StreamStyleSerializationClientBuilder retryOptions(RetryOptions retryOptions) {
+ this.retryOptions = retryOptions;
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Generated
+ @Override
+ public StreamStyleSerializationClientBuilder addPolicy(HttpPipelinePolicy customPolicy) {
+ Objects.requireNonNull(customPolicy, "'customPolicy' cannot be null.");
+ pipelinePolicies.add(customPolicy);
+ return this;
+ }
+
+ /*
+ * The configuration store that is used during construction of the service client.
+ */
+ @Generated
+ private Configuration configuration;
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Generated
+ @Override
+ public StreamStyleSerializationClientBuilder configuration(Configuration configuration) {
+ this.configuration = configuration;
+ return this;
+ }
+
+ /*
+ * The service endpoint
+ */
+ @Generated
+ private String endpoint;
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Generated
+ @Override
+ public StreamStyleSerializationClientBuilder endpoint(String endpoint) {
+ this.endpoint = endpoint;
+ return this;
+ }
+
+ /*
+ * Service version
+ */
+ @Generated
+ private StreamStyleSerializationServiceVersion serviceVersion;
+
+ /**
+ * Sets Service version.
+ *
+ * @param serviceVersion the serviceVersion value.
+ * @return the StreamStyleSerializationClientBuilder.
+ */
+ @Generated
+ public StreamStyleSerializationClientBuilder serviceVersion(StreamStyleSerializationServiceVersion serviceVersion) {
+ this.serviceVersion = serviceVersion;
+ return this;
+ }
+
+ /*
+ * The retry policy that will attempt to retry failed requests, if applicable.
+ */
+ @Generated
+ private RetryPolicy retryPolicy;
+
+ /**
+ * Sets The retry policy that will attempt to retry failed requests, if applicable.
+ *
+ * @param retryPolicy the retryPolicy value.
+ * @return the StreamStyleSerializationClientBuilder.
+ */
+ @Generated
+ public StreamStyleSerializationClientBuilder retryPolicy(RetryPolicy retryPolicy) {
+ this.retryPolicy = retryPolicy;
+ return this;
+ }
+
+ /**
+ * Builds an instance of StreamStyleSerializationClientImpl with the provided parameters.
+ *
+ * @return an instance of StreamStyleSerializationClientImpl.
+ */
+ @Generated
+ private StreamStyleSerializationClientImpl buildInnerClient() {
+ this.validateClient();
+ HttpPipeline localPipeline = (pipeline != null) ? pipeline : createHttpPipeline();
+ StreamStyleSerializationServiceVersion localServiceVersion
+ = (serviceVersion != null) ? serviceVersion : StreamStyleSerializationServiceVersion.getLatest();
+ StreamStyleSerializationClientImpl client = new StreamStyleSerializationClientImpl(localPipeline,
+ JacksonAdapter.createDefaultSerializerAdapter(), this.endpoint, localServiceVersion);
+ 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;
+ HttpLogOptions localHttpLogOptions = this.httpLogOptions == null ? new HttpLogOptions() : this.httpLogOptions;
+ ClientOptions localClientOptions = this.clientOptions == null ? new ClientOptions() : this.clientOptions;
+ List policies = new ArrayList<>();
+ String clientName = PROPERTIES.getOrDefault(SDK_NAME, "UnknownName");
+ String clientVersion = PROPERTIES.getOrDefault(SDK_VERSION, "UnknownVersion");
+ String applicationId = CoreUtils.getApplicationId(localClientOptions, localHttpLogOptions);
+ policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion, buildConfiguration));
+ policies.add(new RequestIdPolicy());
+ policies.add(new AddHeadersFromContextPolicy());
+ 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));
+ 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)
+ .forEach(p -> policies.add(p));
+ HttpPolicyProviders.addAfterRetryPolicies(policies);
+ policies.add(new HttpLoggingPolicy(localHttpLogOptions));
+ HttpPipeline httpPipeline = new HttpPipelineBuilder().policies(policies.toArray(new HttpPipelinePolicy[0]))
+ .httpClient(httpClient)
+ .clientOptions(localClientOptions)
+ .build();
+ return httpPipeline;
+ }
+
+ /**
+ * Builds an instance of StreamStyleSerializationAsyncClient class.
+ *
+ * @return an instance of StreamStyleSerializationAsyncClient.
+ */
+ @Generated
+ public StreamStyleSerializationAsyncClient buildAsyncClient() {
+ return new StreamStyleSerializationAsyncClient(buildInnerClient().getAssets());
+ }
+
+ /**
+ * Builds an instance of StreamStyleSerializationClient class.
+ *
+ * @return an instance of StreamStyleSerializationClient.
+ */
+ @Generated
+ public StreamStyleSerializationClient buildClient() {
+ return new StreamStyleSerializationClient(buildInnerClient().getAssets());
+ }
+
+ private static final ClientLogger LOGGER = new ClientLogger(StreamStyleSerializationClientBuilder.class);
+}
diff --git a/typespec-tests/src/main/java/com/cadl/streamstyleserialization/StreamStyleSerializationServiceVersion.java b/typespec-tests/src/main/java/com/cadl/streamstyleserialization/StreamStyleSerializationServiceVersion.java
new file mode 100644
index 0000000000..d17797cebc
--- /dev/null
+++ b/typespec-tests/src/main/java/com/cadl/streamstyleserialization/StreamStyleSerializationServiceVersion.java
@@ -0,0 +1,40 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+// Code generated by Microsoft (R) TypeSpec Code Generator.
+
+package com.cadl.streamstyleserialization;
+
+import com.azure.core.util.ServiceVersion;
+
+/**
+ * Service version of StreamStyleSerializationClient.
+ */
+public enum StreamStyleSerializationServiceVersion implements ServiceVersion {
+ /**
+ * Enum value 2023-12-01-preview.
+ */
+ V2023_12_01_PREVIEW("2023-12-01-preview");
+
+ private final String version;
+
+ StreamStyleSerializationServiceVersion(String version) {
+ this.version = version;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getVersion() {
+ return this.version;
+ }
+
+ /**
+ * Gets the latest service version supported by this client library.
+ *
+ * @return The latest {@link StreamStyleSerializationServiceVersion}.
+ */
+ public static StreamStyleSerializationServiceVersion getLatest() {
+ return V2023_12_01_PREVIEW;
+ }
+}
diff --git a/typespec-tests/src/main/java/com/cadl/streamstyleserialization/implementation/AssetsImpl.java b/typespec-tests/src/main/java/com/cadl/streamstyleserialization/implementation/AssetsImpl.java
new file mode 100644
index 0000000000..0a5205f5b7
--- /dev/null
+++ b/typespec-tests/src/main/java/com/cadl/streamstyleserialization/implementation/AssetsImpl.java
@@ -0,0 +1,312 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+// Code generated by Microsoft (R) TypeSpec Code Generator.
+
+package com.cadl.streamstyleserialization.implementation;
+
+import com.azure.core.annotation.ExpectedResponses;
+import com.azure.core.annotation.Get;
+import com.azure.core.annotation.HeaderParam;
+import com.azure.core.annotation.Host;
+import com.azure.core.annotation.HostParam;
+import com.azure.core.annotation.PathParam;
+import com.azure.core.annotation.QueryParam;
+import com.azure.core.annotation.ReturnType;
+import com.azure.core.annotation.ServiceInterface;
+import com.azure.core.annotation.ServiceMethod;
+import com.azure.core.annotation.UnexpectedResponseExceptionType;
+import com.azure.core.exception.ClientAuthenticationException;
+import com.azure.core.exception.HttpResponseException;
+import com.azure.core.exception.ResourceModifiedException;
+import com.azure.core.exception.ResourceNotFoundException;
+import com.azure.core.http.rest.PagedFlux;
+import com.azure.core.http.rest.PagedIterable;
+import com.azure.core.http.rest.PagedResponse;
+import com.azure.core.http.rest.PagedResponseBase;
+import com.azure.core.http.rest.RequestOptions;
+import com.azure.core.http.rest.Response;
+import com.azure.core.http.rest.RestProxy;
+import com.azure.core.util.BinaryData;
+import com.azure.core.util.Context;
+import com.azure.core.util.FluxUtil;
+import com.cadl.streamstyleserialization.StreamStyleSerializationServiceVersion;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import reactor.core.publisher.Mono;
+
+/**
+ * An instance of this class provides access to all the operations defined in Assets.
+ */
+public final class AssetsImpl {
+ /**
+ * The proxy service used to perform REST calls.
+ */
+ private final AssetsService service;
+
+ /**
+ * The service client containing this operation class.
+ */
+ private final StreamStyleSerializationClientImpl client;
+
+ /**
+ * Initializes an instance of AssetsImpl.
+ *
+ * @param client the instance of the service client containing this operation class.
+ */
+ AssetsImpl(StreamStyleSerializationClientImpl client) {
+ this.service = RestProxy.create(AssetsService.class, client.getHttpPipeline(), client.getSerializerAdapter());
+ this.client = client;
+ }
+
+ /**
+ * Gets Service version.
+ *
+ * @return the serviceVersion value.
+ */
+ public StreamStyleSerializationServiceVersion getServiceVersion() {
+ return client.getServiceVersion();
+ }
+
+ /**
+ * The interface defining all the services for StreamStyleSerializationClientAssets to be used by the proxy service
+ * to perform REST calls.
+ */
+ @Host("{endpoint}")
+ @ServiceInterface(name = "StreamStyleSerializa")
+ public interface AssetsService {
+ @Get("/assets")
+ @ExpectedResponses({ 200 })
+ @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 })
+ @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 })
+ @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 })
+ @UnexpectedResponseExceptionType(HttpResponseException.class)
+ Mono> listAssetResource(@HostParam("endpoint") String endpoint,
+ @QueryParam("api-version") String apiVersion, @HeaderParam("accept") String accept,
+ RequestOptions requestOptions, Context context);
+
+ @Get("/assets")
+ @ExpectedResponses({ 200 })
+ @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 })
+ @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 })
+ @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 })
+ @UnexpectedResponseExceptionType(HttpResponseException.class)
+ Response listAssetResourceSync(@HostParam("endpoint") String endpoint,
+ @QueryParam("api-version") String apiVersion, @HeaderParam("accept") String accept,
+ RequestOptions requestOptions, Context context);
+
+ @Get("{nextLink}")
+ @ExpectedResponses({ 200 })
+ @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 })
+ @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 })
+ @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 })
+ @UnexpectedResponseExceptionType(HttpResponseException.class)
+ Mono> listAssetResourceNext(@PathParam(value = "nextLink", encoded = true) String nextLink,
+ @HostParam("endpoint") String endpoint, @HeaderParam("accept") String accept, RequestOptions requestOptions,
+ Context context);
+
+ @Get("{nextLink}")
+ @ExpectedResponses({ 200 })
+ @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 })
+ @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 })
+ @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 })
+ @UnexpectedResponseExceptionType(HttpResponseException.class)
+ Response listAssetResourceNextSync(@PathParam(value = "nextLink", encoded = true) String nextLink,
+ @HostParam("endpoint") String endpoint, @HeaderParam("accept") String accept, RequestOptions requestOptions,
+ Context context);
+ }
+
+ /**
+ * Retrieve a list of assets for the provided search parameters.
+ * Response Body Schema
+ *
+ * {@code
+ * {
+ * kind: String (Required)
+ * id: String (Required)
+ * name: String (Optional)
+ * }
+ * }
+ *
+ * @param requestOptions The options to configure the HTTP request before HTTP client sends it.
+ * @throws HttpResponseException thrown if the request is rejected by server.
+ * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
+ * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
+ * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
+ * @return paged collection of AssetResource items along with {@link PagedResponse} on successful completion of
+ * {@link Mono}.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ private Mono> listAssetResourceSinglePageAsync(RequestOptions requestOptions) {
+ final String accept = "application/json";
+ return FluxUtil
+ .withContext(context -> service.listAssetResource(this.client.getEndpoint(),
+ this.client.getServiceVersion().getVersion(), accept, requestOptions, context))
+ .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(),
+ getValues(res.getValue(), "value"), getNextLink(res.getValue(), "nextLink"), null));
+ }
+
+ /**
+ * Retrieve a list of assets for the provided search parameters.
+ * Response Body Schema
+ *
+ * {@code
+ * {
+ * kind: String (Required)
+ * id: String (Required)
+ * name: String (Optional)
+ * }
+ * }
+ *
+ * @param requestOptions The options to configure the HTTP request before HTTP client sends it.
+ * @throws HttpResponseException thrown if the request is rejected by server.
+ * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
+ * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
+ * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
+ * @return paged collection of AssetResource items as paginated response with {@link PagedFlux}.
+ */
+ @ServiceMethod(returns = ReturnType.COLLECTION)
+ public PagedFlux listAssetResourceAsync(RequestOptions requestOptions) {
+ RequestOptions requestOptionsForNextPage = new RequestOptions();
+ requestOptionsForNextPage.setContext(
+ requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : Context.NONE);
+ return new PagedFlux<>(() -> listAssetResourceSinglePageAsync(requestOptions),
+ nextLink -> listAssetResourceNextSinglePageAsync(nextLink, requestOptionsForNextPage));
+ }
+
+ /**
+ * Retrieve a list of assets for the provided search parameters.
+ * Response Body Schema
+ *
+ * {@code
+ * {
+ * kind: String (Required)
+ * id: String (Required)
+ * name: String (Optional)
+ * }
+ * }
+ *
+ * @param requestOptions The options to configure the HTTP request before HTTP client sends it.
+ * @throws HttpResponseException thrown if the request is rejected by server.
+ * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
+ * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
+ * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
+ * @return paged collection of AssetResource items along with {@link PagedResponse}.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ private PagedResponse listAssetResourceSinglePage(RequestOptions requestOptions) {
+ final String accept = "application/json";
+ Response res = service.listAssetResourceSync(this.client.getEndpoint(),
+ this.client.getServiceVersion().getVersion(), accept, requestOptions, Context.NONE);
+ return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(),
+ getValues(res.getValue(), "value"), getNextLink(res.getValue(), "nextLink"), null);
+ }
+
+ /**
+ * Retrieve a list of assets for the provided search parameters.
+ * Response Body Schema
+ *
+ * {@code
+ * {
+ * kind: String (Required)
+ * id: String (Required)
+ * name: String (Optional)
+ * }
+ * }
+ *
+ * @param requestOptions The options to configure the HTTP request before HTTP client sends it.
+ * @throws HttpResponseException thrown if the request is rejected by server.
+ * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
+ * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
+ * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
+ * @return paged collection of AssetResource items as paginated response with {@link PagedIterable}.
+ */
+ @ServiceMethod(returns = ReturnType.COLLECTION)
+ public PagedIterable listAssetResource(RequestOptions requestOptions) {
+ RequestOptions requestOptionsForNextPage = new RequestOptions();
+ requestOptionsForNextPage.setContext(
+ requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : Context.NONE);
+ return new PagedIterable<>(() -> listAssetResourceSinglePage(requestOptions),
+ nextLink -> listAssetResourceNextSinglePage(nextLink, requestOptionsForNextPage));
+ }
+
+ /**
+ * Get the next page of items.
+ * Response Body Schema
+ *
+ * {@code
+ * {
+ * kind: String (Required)
+ * id: String (Required)
+ * name: String (Optional)
+ * }
+ * }
+ *
+ * @param nextLink The URL to get the next list of items.
+ * @param requestOptions The options to configure the HTTP request before HTTP client sends it.
+ * @throws HttpResponseException thrown if the request is rejected by server.
+ * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
+ * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
+ * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
+ * @return paged collection of AssetResource items along with {@link PagedResponse} on successful completion of
+ * {@link Mono}.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ private Mono> listAssetResourceNextSinglePageAsync(String nextLink,
+ RequestOptions requestOptions) {
+ final String accept = "application/json";
+ return FluxUtil
+ .withContext(context -> service.listAssetResourceNext(nextLink, this.client.getEndpoint(), accept,
+ requestOptions, context))
+ .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(),
+ getValues(res.getValue(), "value"), getNextLink(res.getValue(), "nextLink"), null));
+ }
+
+ /**
+ * Get the next page of items.
+ * Response Body Schema
+ *
+ * {@code
+ * {
+ * kind: String (Required)
+ * id: String (Required)
+ * name: String (Optional)
+ * }
+ * }
+ *
+ * @param nextLink The URL to get the next list of items.
+ * @param requestOptions The options to configure the HTTP request before HTTP client sends it.
+ * @throws HttpResponseException thrown if the request is rejected by server.
+ * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
+ * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
+ * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
+ * @return paged collection of AssetResource items along with {@link PagedResponse}.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ private PagedResponse listAssetResourceNextSinglePage(String nextLink, RequestOptions requestOptions) {
+ final String accept = "application/json";
+ Response res = service.listAssetResourceNextSync(nextLink, this.client.getEndpoint(), accept,
+ requestOptions, Context.NONE);
+ return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(),
+ getValues(res.getValue(), "value"), getNextLink(res.getValue(), "nextLink"), null);
+ }
+
+ private List getValues(BinaryData binaryData, String path) {
+ try {
+ Map, ?> obj = binaryData.toObject(Map.class);
+ List> values = (List>) obj.get(path);
+ return values.stream().map(BinaryData::fromObject).collect(Collectors.toList());
+ } catch (RuntimeException e) {
+ return null;
+ }
+ }
+
+ private String getNextLink(BinaryData binaryData, String path) {
+ try {
+ Map, ?> obj = binaryData.toObject(Map.class);
+ return (String) obj.get(path);
+ } catch (RuntimeException e) {
+ return null;
+ }
+ }
+}
diff --git a/typespec-tests/src/main/java/com/cadl/streamstyleserialization/implementation/StreamStyleSerializationClientImpl.java b/typespec-tests/src/main/java/com/cadl/streamstyleserialization/implementation/StreamStyleSerializationClientImpl.java
new file mode 100644
index 0000000000..30b27a8c47
--- /dev/null
+++ b/typespec-tests/src/main/java/com/cadl/streamstyleserialization/implementation/StreamStyleSerializationClientImpl.java
@@ -0,0 +1,128 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+// Code generated by Microsoft (R) TypeSpec Code Generator.
+
+package com.cadl.streamstyleserialization.implementation;
+
+import com.azure.core.http.HttpPipeline;
+import com.azure.core.http.HttpPipelineBuilder;
+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;
+import com.cadl.streamstyleserialization.StreamStyleSerializationServiceVersion;
+
+/**
+ * Initializes a new instance of the StreamStyleSerializationClient type.
+ */
+public final class StreamStyleSerializationClientImpl {
+ /**
+ * Server parameter.
+ */
+ private final String endpoint;
+
+ /**
+ * Gets Server parameter.
+ *
+ * @return the endpoint value.
+ */
+ public String getEndpoint() {
+ return this.endpoint;
+ }
+
+ /**
+ * Service version.
+ */
+ private final StreamStyleSerializationServiceVersion serviceVersion;
+
+ /**
+ * Gets Service version.
+ *
+ * @return the serviceVersion value.
+ */
+ public StreamStyleSerializationServiceVersion getServiceVersion() {
+ return this.serviceVersion;
+ }
+
+ /**
+ * 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.
+ */
+ 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 AssetsImpl object to access its operations.
+ */
+ private final AssetsImpl assets;
+
+ /**
+ * Gets the AssetsImpl object to access its operations.
+ *
+ * @return the AssetsImpl object.
+ */
+ public AssetsImpl getAssets() {
+ return this.assets;
+ }
+
+ /**
+ * Initializes an instance of StreamStyleSerializationClient client.
+ *
+ * @param endpoint Server parameter.
+ * @param serviceVersion Service version.
+ */
+ public StreamStyleSerializationClientImpl(String endpoint, StreamStyleSerializationServiceVersion serviceVersion) {
+ this(new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy()).build(),
+ JacksonAdapter.createDefaultSerializerAdapter(), endpoint, serviceVersion);
+ }
+
+ /**
+ * Initializes an instance of StreamStyleSerializationClient client.
+ *
+ * @param httpPipeline The HTTP pipeline to send requests through.
+ * @param endpoint Server parameter.
+ * @param serviceVersion Service version.
+ */
+ public StreamStyleSerializationClientImpl(HttpPipeline httpPipeline, String endpoint,
+ StreamStyleSerializationServiceVersion serviceVersion) {
+ this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter(), endpoint, serviceVersion);
+ }
+
+ /**
+ * Initializes an instance of StreamStyleSerializationClient client.
+ *
+ * @param httpPipeline The HTTP pipeline to send requests through.
+ * @param serializerAdapter The serializer to serialize an object into a string.
+ * @param endpoint Server parameter.
+ * @param serviceVersion Service version.
+ */
+ public StreamStyleSerializationClientImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter,
+ String endpoint, StreamStyleSerializationServiceVersion serviceVersion) {
+ this.httpPipeline = httpPipeline;
+ this.serializerAdapter = serializerAdapter;
+ this.endpoint = endpoint;
+ this.serviceVersion = serviceVersion;
+ this.assets = new AssetsImpl(this);
+ }
+}
diff --git a/typespec-tests/src/main/java/com/cadl/streamstyleserialization/implementation/package-info.java b/typespec-tests/src/main/java/com/cadl/streamstyleserialization/implementation/package-info.java
new file mode 100644
index 0000000000..aeb4feceb8
--- /dev/null
+++ b/typespec-tests/src/main/java/com/cadl/streamstyleserialization/implementation/package-info.java
@@ -0,0 +1,11 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+// Code generated by Microsoft (R) TypeSpec Code Generator.
+
+/**
+ *
+ * Package containing the implementations for StreamStyleSerialization.
+ * stream-style-serialization API.
+ *
+ */
+package com.cadl.streamstyleserialization.implementation;
diff --git a/typespec-tests/src/main/java/com/cadl/streamstyleserialization/models/AsAsset.java b/typespec-tests/src/main/java/com/cadl/streamstyleserialization/models/AsAsset.java
new file mode 100644
index 0000000000..6514071199
--- /dev/null
+++ b/typespec-tests/src/main/java/com/cadl/streamstyleserialization/models/AsAsset.java
@@ -0,0 +1,143 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+// Code generated by Microsoft (R) TypeSpec Code Generator.
+
+package com.cadl.streamstyleserialization.models;
+
+import com.azure.core.annotation.Generated;
+import com.azure.core.annotation.Immutable;
+import com.azure.core.util.CoreUtils;
+import com.azure.json.JsonReader;
+import com.azure.json.JsonToken;
+import com.azure.json.JsonWriter;
+import java.io.IOException;
+import java.time.OffsetDateTime;
+import java.time.format.DateTimeFormatter;
+
+/**
+ * The AsAsset model.
+ */
+@Immutable
+public final class AsAsset extends InventoryAsset {
+ /*
+ * The asn property.
+ */
+ @Generated
+ private Long asn;
+
+ /*
+ * The firstSeen property.
+ */
+ @Generated
+ private OffsetDateTime firstSeen;
+
+ /*
+ * The lastSeen property.
+ */
+ @Generated
+ private OffsetDateTime lastSeen;
+
+ /*
+ * The count property.
+ */
+ @Generated
+ private Long count;
+
+ /**
+ * Creates an instance of AsAsset class.
+ */
+ @Generated
+ private AsAsset() {
+ }
+
+ /**
+ * Get the asn property: The asn property.
+ *
+ * @return the asn value.
+ */
+ @Generated
+ public Long getAsn() {
+ return this.asn;
+ }
+
+ /**
+ * Get the firstSeen property: The firstSeen property.
+ *
+ * @return the firstSeen value.
+ */
+ @Generated
+ public OffsetDateTime getFirstSeen() {
+ return this.firstSeen;
+ }
+
+ /**
+ * Get the lastSeen property: The lastSeen property.
+ *
+ * @return the lastSeen value.
+ */
+ @Generated
+ public OffsetDateTime getLastSeen() {
+ return this.lastSeen;
+ }
+
+ /**
+ * Get the count property: The count property.
+ *
+ * @return the count value.
+ */
+ @Generated
+ public Long getCount() {
+ return this.count;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Generated
+ @Override
+ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
+ jsonWriter.writeStartObject();
+ jsonWriter.writeNumberField("asn", this.asn);
+ jsonWriter.writeStringField("firstSeen",
+ this.firstSeen == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.firstSeen));
+ jsonWriter.writeStringField("lastSeen",
+ this.lastSeen == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.lastSeen));
+ jsonWriter.writeNumberField("count", this.count);
+ return jsonWriter.writeEndObject();
+ }
+
+ /**
+ * Reads an instance of AsAsset from the JsonReader.
+ *
+ * @param jsonReader The JsonReader being read.
+ * @return An instance of AsAsset 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 AsAsset.
+ */
+ @Generated
+ public static AsAsset fromJson(JsonReader jsonReader) throws IOException {
+ return jsonReader.readObject(reader -> {
+ AsAsset deserializedAsAsset = new AsAsset();
+ while (reader.nextToken() != JsonToken.END_OBJECT) {
+ String fieldName = reader.getFieldName();
+ reader.nextToken();
+
+ if ("asn".equals(fieldName)) {
+ deserializedAsAsset.asn = reader.getNullable(JsonReader::getLong);
+ } else if ("firstSeen".equals(fieldName)) {
+ deserializedAsAsset.firstSeen = reader
+ .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString()));
+ } else if ("lastSeen".equals(fieldName)) {
+ deserializedAsAsset.lastSeen = reader
+ .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString()));
+ } else if ("count".equals(fieldName)) {
+ deserializedAsAsset.count = reader.getNullable(JsonReader::getLong);
+ } else {
+ reader.skipChildren();
+ }
+ }
+
+ return deserializedAsAsset;
+ });
+ }
+}
diff --git a/typespec-tests/src/main/java/com/cadl/streamstyleserialization/models/AsAssetResource.java b/typespec-tests/src/main/java/com/cadl/streamstyleserialization/models/AsAssetResource.java
new file mode 100644
index 0000000000..4cc38a3755
--- /dev/null
+++ b/typespec-tests/src/main/java/com/cadl/streamstyleserialization/models/AsAssetResource.java
@@ -0,0 +1,98 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+// Code generated by Microsoft (R) TypeSpec Code Generator.
+
+package com.cadl.streamstyleserialization.models;
+
+import com.azure.core.annotation.Generated;
+import com.azure.core.annotation.Immutable;
+import com.azure.json.JsonReader;
+import com.azure.json.JsonToken;
+import com.azure.json.JsonWriter;
+import java.io.IOException;
+
+/**
+ * The AsAssetResource model.
+ */
+@Immutable
+public final class AsAssetResource extends AssetResource {
+ /*
+ * asset
+ */
+ @Generated
+ private final AsAsset asset;
+
+ /**
+ * Creates an instance of AsAssetResource class.
+ *
+ * @param asset the asset value to set.
+ */
+ @Generated
+ private AsAssetResource(AsAsset asset) {
+ this.asset = asset;
+ this.kind = "as";
+ }
+
+ /**
+ * Get the asset property: asset.
+ *
+ * @return the asset value.
+ */
+ @Generated
+ public AsAsset getAsset() {
+ return this.asset;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Generated
+ @Override
+ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
+ jsonWriter.writeStartObject();
+ toJsonShared(jsonWriter);
+ jsonWriter.writeJsonField("asset", this.asset);
+ return jsonWriter.writeEndObject();
+ }
+
+ /**
+ * Reads an instance of AsAssetResource from the JsonReader.
+ *
+ * @param jsonReader The JsonReader being read.
+ * @return An instance of AsAssetResource 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 AsAssetResource.
+ */
+ @Generated
+ public static AsAssetResource fromJson(JsonReader jsonReader) throws IOException {
+ return jsonReader.readObject(reader -> {
+ String id = null;
+ String name = null;
+ AsAsset asset = null;
+ String kind = "as";
+ while (reader.nextToken() != JsonToken.END_OBJECT) {
+ String fieldName = reader.getFieldName();
+ reader.nextToken();
+
+ if ("id".equals(fieldName)) {
+ id = reader.getString();
+ } else if ("name".equals(fieldName)) {
+ name = reader.getString();
+ } else if ("asset".equals(fieldName)) {
+ asset = AsAsset.fromJson(reader);
+ } else if ("kind".equals(fieldName)) {
+ kind = reader.getString();
+ } else {
+ reader.skipChildren();
+ }
+ }
+ AsAssetResource deserializedAsAssetResource = new AsAssetResource(asset);
+ deserializedAsAssetResource.setId(id);
+ deserializedAsAssetResource.setName(name);
+ deserializedAsAssetResource.kind = kind;
+
+ return deserializedAsAssetResource;
+ });
+ }
+}
diff --git a/typespec-tests/src/main/java/com/cadl/streamstyleserialization/models/AssetResource.java b/typespec-tests/src/main/java/com/cadl/streamstyleserialization/models/AssetResource.java
new file mode 100644
index 0000000000..8d24448244
--- /dev/null
+++ b/typespec-tests/src/main/java/com/cadl/streamstyleserialization/models/AssetResource.java
@@ -0,0 +1,183 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+// Code generated by Microsoft (R) TypeSpec Code Generator.
+
+package com.cadl.streamstyleserialization.models;
+
+import com.azure.core.annotation.Generated;
+import com.azure.core.annotation.Immutable;
+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 items in the current page of results.
+ */
+@Immutable
+public class AssetResource implements JsonSerializable {
+ /*
+ * Discriminator property for AssetResource.
+ */
+ @Generated
+ String kind;
+
+ /*
+ * The system generated unique id for the resource.
+ */
+ @Generated
+ private String id;
+
+ /*
+ * The caller provided unique name for the resource.
+ */
+ @Generated
+ private String name;
+
+ /**
+ * Creates an instance of AssetResource class.
+ */
+ @Generated
+ protected AssetResource() {
+ this.kind = "AssetResource";
+ }
+
+ /**
+ * Get the kind property: Discriminator property for AssetResource.
+ *
+ * @return the kind value.
+ */
+ @Generated
+ public String getKind() {
+ return this.kind;
+ }
+
+ /**
+ * Get the id property: The system generated unique id for the resource.
+ *
+ * @return the id value.
+ */
+ @Generated
+ public String getId() {
+ return this.id;
+ }
+
+ /**
+ * Set the id property: The system generated unique id for the resource.
+ *
+ * @param id the id value to set.
+ * @return the AssetResource object itself.
+ */
+ @Generated
+ AssetResource setId(String id) {
+ this.id = id;
+ return this;
+ }
+
+ /**
+ * Get the name property: The caller provided unique name for the resource.
+ *
+ * @return the name value.
+ */
+ @Generated
+ public String getName() {
+ return this.name;
+ }
+
+ /**
+ * Set the name property: The caller provided unique name for the resource.
+ *
+ * @param name the name value to set.
+ * @return the AssetResource object itself.
+ */
+ @Generated
+ AssetResource setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Generated
+ @Override
+ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
+ jsonWriter.writeStartObject();
+ toJsonShared(jsonWriter);
+ return jsonWriter.writeEndObject();
+ }
+
+ void toJsonShared(JsonWriter jsonWriter) throws IOException {
+ jsonWriter.writeStringField("kind", this.kind);
+ jsonWriter.writeStringField("name", this.name);
+ }
+
+ /**
+ * Reads an instance of AssetResource from the JsonReader.
+ *
+ * @param jsonReader The JsonReader being read.
+ * @return An instance of AssetResource 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 AssetResource.
+ */
+ @Generated
+ public static AssetResource fromJson(JsonReader jsonReader) throws IOException {
+ return jsonReader.readObject(reader -> {
+ String discriminatorValue = null;
+ try (JsonReader readerToUse = reader.bufferObject()) {
+ readerToUse.nextToken(); // Prepare for reading
+ while (readerToUse.nextToken() != JsonToken.END_OBJECT) {
+ String fieldName = readerToUse.getFieldName();
+ readerToUse.nextToken();
+ if ("kind".equals(fieldName)) {
+ discriminatorValue = readerToUse.getString();
+ break;
+ } else {
+ readerToUse.skipChildren();
+ }
+ }
+ // Use the discriminator value to determine which subtype should be deserialized.
+ if ("as".equals(discriminatorValue)) {
+ return AsAssetResource.fromJson(readerToUse.reset());
+ } else {
+ return fromJsonKnownDiscriminator(readerToUse.reset());
+ }
+ }
+ });
+ }
+
+ @Generated
+ static AssetResource fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOException {
+ return jsonReader.readObject(reader -> {
+ AssetResource deserializedAssetResource = new AssetResource();
+ while (reader.nextToken() != JsonToken.END_OBJECT) {
+ String fieldName = reader.getFieldName();
+ reader.nextToken();
+
+ if (!AssetResource.fromJsonShared(reader, fieldName, deserializedAssetResource)) {
+ reader.skipChildren();
+ }
+ }
+
+ return deserializedAssetResource;
+ });
+ }
+
+ @Generated
+ static boolean fromJsonShared(JsonReader reader, String fieldName, AssetResource deserializedAssetResource)
+ throws IOException {
+ if ("id".equals(fieldName)) {
+ deserializedAssetResource.id = reader.getString();
+ return true;
+ } else if ("kind".equals(fieldName)) {
+ deserializedAssetResource.kind = reader.getString();
+ return true;
+ } else if ("name".equals(fieldName)) {
+ deserializedAssetResource.name = reader.getString();
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/typespec-tests/src/main/java/com/cadl/streamstyleserialization/models/InventoryAsset.java b/typespec-tests/src/main/java/com/cadl/streamstyleserialization/models/InventoryAsset.java
new file mode 100644
index 0000000000..4ffe1d445a
--- /dev/null
+++ b/typespec-tests/src/main/java/com/cadl/streamstyleserialization/models/InventoryAsset.java
@@ -0,0 +1,59 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+// Code generated by Microsoft (R) TypeSpec Code Generator.
+
+package com.cadl.streamstyleserialization.models;
+
+import com.azure.core.annotation.Generated;
+import com.azure.core.annotation.Immutable;
+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 inventory base model created for swagger documentation purpose.
+ */
+@Immutable
+public class InventoryAsset implements JsonSerializable {
+ /**
+ * Creates an instance of InventoryAsset class.
+ */
+ @Generated
+ protected InventoryAsset() {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Generated
+ @Override
+ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
+ jsonWriter.writeStartObject();
+ return jsonWriter.writeEndObject();
+ }
+
+ /**
+ * Reads an instance of InventoryAsset from the JsonReader.
+ *
+ * @param jsonReader The JsonReader being read.
+ * @return An instance of InventoryAsset 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 InventoryAsset.
+ */
+ @Generated
+ public static InventoryAsset fromJson(JsonReader jsonReader) throws IOException {
+ return jsonReader.readObject(reader -> {
+ InventoryAsset deserializedInventoryAsset = new InventoryAsset();
+ while (reader.nextToken() != JsonToken.END_OBJECT) {
+ String fieldName = reader.getFieldName();
+ reader.nextToken();
+
+ reader.skipChildren();
+ }
+
+ return deserializedInventoryAsset;
+ });
+ }
+}
diff --git a/typespec-tests/src/main/java/com/cadl/streamstyleserialization/models/package-info.java b/typespec-tests/src/main/java/com/cadl/streamstyleserialization/models/package-info.java
new file mode 100644
index 0000000000..5f69bc5b19
--- /dev/null
+++ b/typespec-tests/src/main/java/com/cadl/streamstyleserialization/models/package-info.java
@@ -0,0 +1,11 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+// Code generated by Microsoft (R) TypeSpec Code Generator.
+
+/**
+ *
+ * Package containing the data models for StreamStyleSerialization.
+ * stream-style-serialization API.
+ *
+ */
+package com.cadl.streamstyleserialization.models;
diff --git a/typespec-tests/src/main/java/com/cadl/streamstyleserialization/package-info.java b/typespec-tests/src/main/java/com/cadl/streamstyleserialization/package-info.java
new file mode 100644
index 0000000000..6ee7507e3c
--- /dev/null
+++ b/typespec-tests/src/main/java/com/cadl/streamstyleserialization/package-info.java
@@ -0,0 +1,11 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+// Code generated by Microsoft (R) TypeSpec Code Generator.
+
+/**
+ *
+ * Package containing the classes for StreamStyleSerialization.
+ * stream-style-serialization API.
+ *
+ */
+package com.cadl.streamstyleserialization;
diff --git a/typespec-tests/src/main/resources/cadl-streamstyleserialization.properties b/typespec-tests/src/main/resources/cadl-streamstyleserialization.properties
new file mode 100644
index 0000000000..ca812989b4
--- /dev/null
+++ b/typespec-tests/src/main/resources/cadl-streamstyleserialization.properties
@@ -0,0 +1,2 @@
+name=${project.artifactId}
+version=${project.version}
diff --git a/typespec-tests/src/test/java/com/cadl/streamstyleserialization/generated/StreamStyleSerializationClientTestBase.java b/typespec-tests/src/test/java/com/cadl/streamstyleserialization/generated/StreamStyleSerializationClientTestBase.java
new file mode 100644
index 0000000000..66e148f734
--- /dev/null
+++ b/typespec-tests/src/test/java/com/cadl/streamstyleserialization/generated/StreamStyleSerializationClientTestBase.java
@@ -0,0 +1,38 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+// Code generated by Microsoft (R) TypeSpec Code Generator.
+
+package com.cadl.streamstyleserialization.generated;
+
+// The Java test files under 'generated' package are generated for your reference.
+// If you wish to modify these files, please copy them out of the 'generated' package, and modify there.
+// See https://aka.ms/azsdk/dpg/java/tests for guide on adding a test.
+
+import com.azure.core.http.HttpClient;
+import com.azure.core.http.policy.HttpLogDetailLevel;
+import com.azure.core.http.policy.HttpLogOptions;
+import com.azure.core.test.TestMode;
+import com.azure.core.test.TestProxyTestBase;
+import com.azure.core.util.Configuration;
+import com.cadl.streamstyleserialization.StreamStyleSerializationClient;
+import com.cadl.streamstyleserialization.StreamStyleSerializationClientBuilder;
+
+class StreamStyleSerializationClientTestBase extends TestProxyTestBase {
+ protected StreamStyleSerializationClient streamStyleSerializationClient;
+
+ @Override
+ protected void beforeTest() {
+ StreamStyleSerializationClientBuilder streamStyleSerializationClientbuilder
+ = new StreamStyleSerializationClientBuilder()
+ .endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT", "endpoint"))
+ .httpClient(HttpClient.createDefault())
+ .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC));
+ if (getTestMode() == TestMode.PLAYBACK) {
+ streamStyleSerializationClientbuilder.httpClient(interceptorManager.getPlaybackClient());
+ } else if (getTestMode() == TestMode.RECORD) {
+ streamStyleSerializationClientbuilder.addPolicy(interceptorManager.getRecordPolicy());
+ }
+ streamStyleSerializationClient = streamStyleSerializationClientbuilder.buildClient();
+
+ }
+}
diff --git a/typespec-tests/tsp/stream-style-serialization.tsp b/typespec-tests/tsp/stream-style-serialization.tsp
new file mode 100644
index 0000000000..7e3f28d478
--- /dev/null
+++ b/typespec-tests/tsp/stream-style-serialization.tsp
@@ -0,0 +1,72 @@
+import "@typespec/http";
+import "@typespec/rest";
+import "@typespec/versioning";
+import "@azure-tools/typespec-azure-core";
+
+using TypeSpec.Http;
+using TypeSpec.Rest;
+using TypeSpec.Versioning;
+using Azure.Core;
+using Azure.Core.Traits;
+
+@service({
+ title: "StreamStyleSerialization",
+})
+@versioned(Versions)
+@doc("stream-style-serialization API.")
+namespace Cadl.StreamStyleSerialization;
+
+@doc("Azure API versions.")
+enum Versions {
+ @useDependency(Azure.Core.Versions.v1_0_Preview_2)
+ @doc("Preview API version 2023-12-01-preview.")
+ v2023_12_01_preview: "2023-12-01-preview",
+}
+
+@doc("A inventory base model created for swagger documentation purpose")
+model InventoryAsset {}
+
+#suppress "@azure-tools/typespec-azure-core/documentation-required" "Documentation will be added next preview version"
+model AsAsset extends InventoryAsset {
+ asn?: int64;
+ firstSeen?: utcDateTime;
+ lastSeen?: utcDateTime;
+ count?: int64;
+}
+
+#suppress "@azure-tools/typespec-azure-core/documentation-required" "Documentation will be added next preview version"
+model AsAssetResource extends AssetResource {
+ @doc("The kind of AssetResource")
+ kind: "as";
+
+ @doc("asset")
+ asset: AsAsset;
+}
+
+#suppress "@azure-tools/typespec-azure-core/documentation-required" "Documentation will be added next preview version"
+@doc("The items in the current page of results.")
+@discriminator("kind")
+@resource("assets")
+model AssetResource {
+ /** Discriminator property for AssetResource. */
+ #suppress "@azure-tools/typespec-azure-core/no-string-discriminator" "Existing"
+ kind: string;
+
+ @doc("The system generated unique id for the resource.")
+ @key("assetId")
+ @visibility("read")
+ id: string;
+
+ @doc("The caller provided unique name for the resource.")
+ name?: string;
+}
+
+alias ServiceTraits = NoRepeatableRequests & NoConditionalRequests & NoClientRequestId;
+
+alias Operations = Azure.Core.ResourceOperations;
+@tag("Assets")
+@doc("Provides access to inventory assets.")
+interface Assets {
+ @doc("Retrieve a list of assets for the provided search parameters.")
+ listAssetResource is Operations.ResourceList;
+}