---
title: Generated Types
llmstxt: true
---

import { ClientTabs, ClientTabItem } from "@components/client-tabs";

This page documents what type definitions in TypeSpec are generated as in emitted libraries

## Namespace

The namespace for models, enums, and unions will follow the namespace they belong to. You can use `@clientNamespace` to override it if needed.

### Model in namespace

<ClientTabs>
<ClientTabItem lang="typespec" >

```typespec
namespace Service;

model Foo {
  prop: string;
}
```

</ClientTabItem>

<ClientTabItem lang="python">

```python
from service.models import Foo

foo = Foo(prop="hello")
```

</ClientTabItem>
<ClientTabItem lang="csharp" >

```csharp
namespace Service
{
  public partial class Foo
  {
    public string Prop { get; }
  }
}
```

</ClientTabItem>
<ClientTabItem lang="typescript" >

```typescript
export interface Foo {
  prop: string;
}

export function fooSerializer(item: Foo): any {
  return { prop: item["prop"] };
}
```

</ClientTabItem>
<ClientTabItem lang="java" >

As `flavor=azure`, Java emitter generates the model classes under `models` package.

```java
import service.models.Foo;

Foo foo = new Foo("hello");
```

</ClientTabItem>
<ClientTabItem lang="go" >

```go
type Foo struct {
  Prop string `json:"prop"`
}

```

</ClientTabItem>
</ClientTabs>

### Model in sub namespace

<ClientTabs>
<ClientTabItem lang="typespec" >

```typespec
namespace Service;

namespace Container {
  model Foo {
    prop: string;
  }
}
```

</ClientTabItem>

<ClientTabItem lang="python">

```python
from service.container.models import Foo

foo = Foo(prop="hello")
```

</ClientTabItem>
<ClientTabItem lang="csharp" >

```csharp
namespace Service.Container
{
  public partial class Foo
  {
    public string Prop { get; }
  }
}
```

</ClientTabItem>
<ClientTabItem lang="typescript" >

```typescript
export interface Foo {
  prop: string;
}

export function fooSerializer(item: Foo): any {
  return { prop: item["prop"] };
}
```

</ClientTabItem>
<ClientTabItem lang="java" >

As `flavor=azure`, Java emitter generates the model classes under `models` package.

```java
import service.container.models.Foo;

Foo foo = new Foo("hello");
```

</ClientTabItem>
<ClientTabItem lang="go" >

```go
package container

type Foo struct {
  Prop string `json:"prop"`
}

```

</ClientTabItem>
</ClientTabs>

### Model in namespace with renaming

<ClientTabs>
<ClientTabItem lang="typespec" >

```typespec
namespace Service;

@clientNamespace("Service.Container")
model Foo {
  prop: string;
}
```

</ClientTabItem>

<ClientTabItem lang="python">

```python
from service.container.models import Foo

foo = Foo(prop="hello")
```

</ClientTabItem>
<ClientTabItem lang="csharp" >

```csharp
namespace Service.Container
{
  public partial class Foo
  {
    public string Prop { get; }
  }
}
```

</ClientTabItem>
<ClientTabItem lang="typescript" >

```typescript
export interface Foo {
  prop: string;
}

export function fooSerializer(item: Foo): any {
  return { prop: item["prop"] };
}
```

</ClientTabItem>
<ClientTabItem lang="java" >

As `flavor=azure`, Java emitter generates the model classes under `models` package.

```java
import service.container.models.Foo;

Foo foo = new Foo("hello");
```

</ClientTabItem>
<ClientTabItem lang="go" >

```go
package container

type Foo struct {
  Prop *string
}
```

</ClientTabItem>
</ClientTabs>

## Client Documentation

The `@clientDoc` decorator lets you add documentation that will appear in generated client libraries. This is useful for providing additional context, examples, or implementation notes that are only relevant for SDK consumers.

<ClientTabs>
<ClientTabItem lang="typespec" >

```typespec
@doc("This internal model is the base class for shapes")
@clientDoc(
  "Base class for all shape objects that can be drawn on a canvas",
  DocumentationMode.replace
)
model Shape {
  @doc("The coordinates of the shape")
  @clientDoc(
    "The x,y coordinates where the shape will be positioned on the canvas",
    DocumentationMode.replace
  )
  position: Point;
}

@doc("A two-dimensional point")
@clientDoc("Represents a position in a 2D coordinate system", DocumentationMode.replace)
model Point {
  @doc("X coordinate")
  @clientDoc("The horizontal position (increases moving right)", DocumentationMode.replace)
  x: float32;

  @doc("Y coordinate")
  @clientDoc("The vertical position (increases moving down)", DocumentationMode.replace)
  y: float32;
}
```

</ClientTabItem>
<ClientTabItem lang="python">

```python
class Point(_model_base.Model):
    """Represents a position in a 2D coordinate system.

    :param x: The horizontal position (increases moving right)
    :type x: float
    :param y: The vertical position (increases moving down)
    :type y: float
    """

    x: float = rest_field()
    """The horizontal position (increases moving right)."""
    y: float = rest_field()
    """The vertical position (increases moving down)."""

class Shape(_model_base.Model):
    """Base class for all shape objects that can be drawn on a canvas.

    :param position: The x,y coordinates where the shape will be positioned on the canvas
    :type position: Point
    """

    position: Point = rest_field()
    """The x,y coordinates where the shape will be positioned on the canvas."""
```

</ClientTabItem>
<ClientTabItem lang="csharp" >

```csharp
/// <summary>
/// Base class for all shape objects that can be drawn on a canvas
/// </summary>
public partial class Shape
{
    /// <summary>
    /// The x,y coordinates where the shape will be positioned on the canvas
    /// </summary>
    public Point Position { get; set; }
}

/// <summary>
/// Represents a position in a 2D coordinate system
/// </summary>
public partial class Point
{
    /// <summary>
    /// The horizontal position (increases moving right)
    /// </summary>
    public float X { get; set; }

    /// <summary>
    /// The vertical position (increases moving down)
    /// </summary>
    public float Y { get; set; }
}
```

</ClientTabItem>
<ClientTabItem lang="typescript" >

```typescript
/**
 * Base class for all shape objects that can be drawn on a canvas
 */
export interface Shape {
  /**
   * The x,y coordinates where the shape will be positioned on the canvas
   */
  position: Point;
}

/**
 * Represents a position in a 2D coordinate system
 */
export interface Point {
  /**
   * The horizontal position (increases moving right)
   */
  x: number;

  /**
   * The vertical position (increases moving down)
   */
  y: number;
}
```

</ClientTabItem>
<ClientTabItem lang="java" >

```java
/**
 * Base class for all shape objects that can be drawn on a canvas.
 */
@Fluent
public final class Shape {
    /**
     * The x,y coordinates where the shape will be positioned on the canvas.
     */
    private Point position;

    /**
     * Get the position property: The x,y coordinates where the shape will be positioned on the canvas.
     *
     * @return the position value.
     */
    public Point getPosition() {
        return this.position;
    }

    /**
     * Set the position property: The x,y coordinates where the shape will be positioned on the canvas.
     *
     * @param position the position value to set.
     * @return the Shape object itself.
     */
    public Shape setPosition(Point position) {
        this.position = position;
        return this;
    }
}

/**
 * Represents a position in a 2D coordinate system.
 */
@Fluent
public final class Point {
    /**
     * The horizontal position (increases moving right).
     */
    private float x;

    /**
     * The vertical position (increases moving down).
     */
    private float y;

    /**
     * Get the x property: The horizontal position (increases moving right).
     *
     * @return the x value.
     */
    public float getX() {
        return this.x;
    }

    /**
     * Set the x property: The horizontal position (increases moving right).
     *
     * @param x the x value to set.
     * @return the Point object itself.
     */
    public Point setX(float x) {
        this.x = x;
        return this;
    }

    /**
     * Get the y property: The vertical position (increases moving down).
     *
     * @return the y value.
     */
    public float getY() {
        return this.y;
    }

    /**
     * Set the y property: The vertical position (increases moving down).
     *
     * @param y the y value to set.
     * @return the Point object itself.
     */
    public Point setY(float y) {
        this.y = y;
        return this;
    }
}
```

</ClientTabItem>
<ClientTabItem lang="go">

```go
// Shape - Base class for all shape objects that can be drawn on a canvas
type Shape struct {
	// Position - The x,y coordinates where the shape will be positioned on the canvas
	Position *Point
}

// Point - Represents a position in a 2D coordinate system
type Point struct {
	// X - The horizontal position (increases moving right)
	X *float32

	// Y - The vertical position (increases moving down)
	Y *float32
}
```

</ClientTabItem>
</ClientTabs>

The `@clientDoc` decorator can be used on everything that the `@doc` decorator can be applied to.

When both `@doc` and `@clientDoc` are present, the generated code outputs the final documentation depending on the mode that you called `@clientDoc` with.
If called with `replace`, `@clientDoc` replaces `@doc` completely. If called with `append`, `@clientDoc` is appended onto `@doc`.

## Using `@alternateType` to Reference External Types

The `@alternateType` decorator allows you to override the emitted type for a model, union, or enum in generated client libraries. With recent updates, you can now reference types defined in external namespaces or imported libraries.

### Example: Referencing an External Type

Suppose you want your generated client library to use a type from an external package instead of the default emitted type.

```typespec
@alternateType(
  {
    fullyQualifiedName: "externallib.ExternalModel",
    package: "externallib",
  },
  "python"
)
model MyModel {
  prop: string;
}
```

In this example, instead of generating `MyModel` in the Python sdk, the emitter will reference `ExternalModel` from `externallib` instead.

### Use Cases

- Integrating with shared types from other services or libraries.
- Ensuring consistency across multiple SDKs by reusing common models.
- Reducing duplication when types are already defined elsewhere.

### Notes

- The referenced type should be compatible with the intended usage in the generated client library.
- When a type is marked as an external alternate type, TCGC assigns it the `External` usage flag. Types that are only reachable through external types will also only have the `External` usage flag — they will not receive `Input` or `Output` flags. This signals to emitters that serialization and deserialization code does not need to be generated for these types, since the external package handles them.

## Client Default Values (Legacy)

:::caution
The `@clientDefaultValue` decorator is legacy functionality that should **only** be used to mitigate SDK breaking changes for brownfield services. **New services should NOT use this decorator.** Instead, use standard TypeSpec patterns for default values.
:::

The `@Azure.ClientGenerator.Core.Legacy.clientDefaultValue` decorator allows you to set a client-level default value for a model property or operation parameter. This is primarily intended for maintaining backward compatibility with existing SDK users who may rely on default values that were previously generated from Swagger definitions.

### Model Property Default Values

Use `@clientDefaultValue` on model properties when you need to specify a default value that will be used in the generated SDK code.

<ClientTabs>
<ClientTabItem lang="typespec" >

```typespec
model RequestOptions {
  @Azure.ClientGenerator.Core.Legacy.clientDefaultValue(30)
  timeout?: int32;

  @Azure.ClientGenerator.Core.Legacy.clientDefaultValue("standard")
  tier?: string;

  @Azure.ClientGenerator.Core.Legacy.clientDefaultValue(false)
  enableRetry?: boolean;
}
```

</ClientTabItem>

<ClientTabItem lang="python">

```python
# Not supported yet in python and track status in https://github.com/microsoft/typespec/issues/9198
```

</ClientTabItem>

<ClientTabItem lang="csharp" >

```csharp
TODO
```

</ClientTabItem>

<ClientTabItem lang="typescript" >

```typescript
TODO;
```

</ClientTabItem>

<ClientTabItem lang="java" >

```java
TODO
```

</ClientTabItem>

<ClientTabItem lang="go" >

```go
TODO
```

</ClientTabItem>
</ClientTabs>

### Operation Parameter Default Values

Use `@clientDefaultValue` on operation parameters when you need to specify a default value for query parameters, headers, or other operation inputs.

<ClientTabs>
<ClientTabItem lang="typespec" >

```typespec
op getItems(
  @Azure.ClientGenerator.Core.Legacy.clientDefaultValue(10)
  @query
  pageSize?: int32,

  @Azure.ClientGenerator.Core.Legacy.clientDefaultValue("desc")
  @query
  sortOrder?: string,
): Item[];
```

</ClientTabItem>

<ClientTabItem lang="python">

```python
    def get_items(
        self, *, page_size: int = 10, sort_order: str = "desc", **kwargs: Any
    ) -> list[_models.Item]:
```

</ClientTabItem>

<ClientTabItem lang="csharp" >

```csharp
TODO
```

</ClientTabItem>

<ClientTabItem lang="typescript" >

```typescript
TODO;
```

</ClientTabItem>

<ClientTabItem lang="java" >

```java
TODO
```

</ClientTabItem>

<ClientTabItem lang="go" >

```go
TODO
```

</ClientTabItem>
</ClientTabs>

### Language-Specific Scoping

You can also scope the default value to specific languages using the `scope` parameter:

<ClientTabs>
<ClientTabItem lang="typespec" >

```typespec
model Config {
  // Apply default only for Python
  @Azure.ClientGenerator.Core.Legacy.clientDefaultValue(false, "python")
  enableCache?: boolean;

  // Apply default for all languages except Java and Python
  @Azure.ClientGenerator.Core.Legacy.clientDefaultValue(100, "!(java, python)")
  maxRetries?: int32;
}
```

</ClientTabItem>
</ClientTabs>

## Models

### Models with additional properties of any type

#### Additional properties of any type

<ClientTabs>
<ClientTabItem lang="typespec" >

Recommend usage:

```typespec
model Animal {
  name: string;
  kind: string;
  ...Record<unknown>;
}
```

Other usages:

```typespec
model Animal extends Record<unknown> {
  name: string;
  kind: string;
}
```

```typespec
model Animal is Record<unknown> {
  name: string;
  kind: string;
}
```

</ClientTabItem>
<ClientTabItem lang="python">

Python models are designed to support adding any additional properties.

```python
from .. import _model_base
from .._model_base import rest_field

class Animal(_model_base.Model):

    name: str = rest_field()
    kind: str = rest_field()

animal = Animal(name="Tom", kind="Cat")
animal["friend"] = "Jerry"
animal["age"] = 5
```

</ClientTabItem>
<ClientTabItem lang="csharp" >

```csharp
public partial class Animal : IJsonModel<Animal> {
    public Animal(string name, string kind);

    public string Name { get; }
    public string Kind { get; }

    public IDictionary<string, BinaryData> AdditionalProperties { get; }
}
```

</ClientTabItem>
<ClientTabItem lang="typescript" >

```ts
// JS CodeGen for both legacy and non legacy
export interface Animal extends Record<string, any> {
  name: string;
  kind: string;
}
```

</ClientTabItem>
<ClientTabItem lang="java" >

```java
@Fluent
public final class Animal implements JsonSerializable<Animal> {
    public Animal(String name, String kind);
    public String getName();
    public String getKind();
    public Map<String, Object> getAdditionalProperties();
    public Animal setAdditionalProperties(Map<String, Object> additionalProperties);
}
```

</ClientTabItem>
<ClientTabItem lang="go" >

```go
// Input: Animal (with known fields + optional unknowns)
type Animal struct {
  Name *string
  Kind *string
  AdditionalProperties map[string]interface{}
}

```

</ClientTabItem>

</ClientTabs>

#### Additional properties of specific type

<ClientTabs>
<ClientTabItem lang="typespec" >

```typespec
model AnimalProperty {
  category: string;
  value: unknown;
}

model Animal {
  name: string;
  kind: string;
  ...Record<AnimalProperty>;
}
```

</ClientTabItem>
<ClientTabItem lang="python">

Python models are designed to support adding any additional properties.

```python
from typing import Any
from .. import _model_base
from .._model_base import rest_field

class Animal(_model_base.Model):

    name: str = rest_field()
    kind: str = rest_field()

class AnimalProperty(_model_base.Model):

    category: str = rest_field()
    value: Any = rest_field()

animal = Animal(name="Tom", kind="Cat")
animal["friend"] = AnimalProperty(category="relationship", value="Jerry")
animal["age"] = AnimalProperty(category="attribute", value=5)
```

</ClientTabItem>
<ClientTabItem lang="csharp" >

Due to currently there is no way to know whether a Json could be correctly mapped into the specified type in `.Net`, we currently generate any non-primitive value type in additional properties property as `BinaryData`.

For typespec:

```typespec
model Animal {
  name: string;
  kind: string;
  ...Record<AnimalProperty>;
}
```

The `C#` generated code is the same as if the type is `unknown`:

```csharp
public partial class Animal : IJsonModel<Animal>
{
    public Animal(string name, string kind);

    public string Name { get; }
    public string Kind { get; }

    public IDictionary<string, BinaryData> AdditionalProperties { get; }
}
```

For typespec with additional properties of primitive types:

```typespec
model Animal {
  name: string;
  kind: string;
  ...Record<string>;
}
```

The `C#` generated code still has the specified type in `AdditionalProperties` property:

```csharp
public partial class Animal : IJsonModel<Animal>
{
    public Animal(string name, string kind);

    public string Name { get; }
    public string Kind { get; }

    public IDictionary<string, string> AdditionalProperties { get; }
}
```

</ClientTabItem>
<ClientTabItem lang="typescript" >

```ts
// JS CodeGen for legacy clients
export interface AnimalProperty {
  category: string;
  value: any;
}
export interface Animal extends Record<string, any> {
  name: string;
  kind: string;
}

// JS CodeGen for non-legacy clients
export interface AnimalProperty {
  category: string;
  value: any;
}
export interface Animal {
  name: string;
  kind: string;
  additionalProperties: Record<string, AnimalProperty>;
}
```

</ClientTabItem>
<ClientTabItem lang="java" >

```java
@Fluent
public final class Animal implements JsonSerializable<Animal> {
    public Animal(String name, String kind);
    public String getName();
    public String getKind();
    public Map<String, AnimalProperty> getAdditionalProperties();
    public Animal setAdditionalProperties(Map<String, AnimalProperty> additionalProperties);
}

```

</ClientTabItem>
<ClientTabItem lang="go" >

```go
type AnimalProperty struct {
  Category *string
  Value    interface{}
}

type Animal struct {
  Name *string
  Kind *string
  AdditionalProperties map[string]AnimalProperty
}

```

</ClientTabItem>
</ClientTabs>

#### Additional properties of union type

<ClientTabs>
<ClientTabItem lang="typespec" >

```typespec
model Animal {
  name: string;
  kind: string;
  ...Record<string>;
  ...Record<int32>;
}
```

</ClientTabItem>
<ClientTabItem lang="python">

Python models are designed to support adding any additional properties.

```python
from .. import _model_base
from .._model_base import rest_field

class Animal(_model_base.Model):

    name: str = rest_field()
    kind: str = rest_field()

animal = Animal(name="Tom", kind="Cat")
animal["friend"] = "Jerry"
animal["age"] = 5
```

</ClientTabItem>
<ClientTabItem lang="csharp" >

```csharp
public partial class Animal : IJsonModel<Animal>
{
    public Animal(string name, string kind);

    public string Name { get; }
    public string Kind { get; }

    public IDictionary<string, BinaryData> AdditionalProperties { get; }
}
```

</ClientTabItem>
<ClientTabItem lang="typescript" >

```ts
// JS CodeGen for legacy and non-legacy clients
export interface Animal extends Record<string, string | number> {
  name: string;
  kind: string;
}
```

</ClientTabItem>
<ClientTabItem lang="java" >

```java
@Fluent
public final class Animal implements JsonSerializable<Animal> {
    public Animal(String name, String kind);
    public String getName();
    public String getKind();
    public Map<String, BinaryData> getAdditionalProperties();
    public Animal setAdditionalProperties(Map<String, BinaryData> additionalProperties);
}
```

</ClientTabItem>
<ClientTabItem lang="go" >
```go
type Animal struct {
	Name string
	Kind string
	AdditionalProperties map[string]interface{}
}
```
</ClientTabItem>
</ClientTabs>

#### Additional properties of nullable type

<ClientTabs>
<ClientTabItem lang="typespec" >

```typespec
model Animal {
  name: string;
  kind: string;
  ...Record<string | null>;
}
```

</ClientTabItem>
<ClientTabItem lang="python">

Python models are designed to support adding any additional properties.

```python
from .. import _model_base
from .._model_base import rest_field

class Animal(_model_base.Model):

    name: str = rest_field()
    kind: str = rest_field()

animal = Animal(name="Tom", kind="Cat")
animal["friend"] = "Jerry"
animal["alert"] = None
```

</ClientTabItem>
<ClientTabItem lang="csharp" >

```csharp
public partial class Animal : IJsonModel<Animal>
{
    public Animal(string name, string kind);

    public string Name { get; }
    public string Kind { get; }

    public IDictionary<string, string> AdditionalProperties { get; }
}
```

</ClientTabItem>
<ClientTabItem lang="typescript" >

```ts
// JS CodeGen for legacy and non-legacy clients
export interface Animal extends Record<string, string | null> {
  name: string;
  kind: string;
}
```

</ClientTabItem>

<ClientTabItem lang="java" >

```java
@Fluent
public final class Animal implements JsonSerializable<Animal> {
    public Animal(String name, String kind);
    public String getName();
    public String getKind();
    public Map<String, String> getAdditionalProperties();
    public Animal setAdditionalProperties(Map<String, String> additionalProperties);
}

```

</ClientTabItem>
<ClientTabItem lang="go" >

```go
type Animal struct {
    // REQUIRED
    Kind *string
    // REQUIRED
    Name                 *string
    AdditionalProperties map[string]*string
}
```

</ClientTabItem>
</ClientTabs>

### Discriminator

TypeSpec uses `@discriminator` decorator to add a discriminator to a model.

<ClientTabs>
<ClientTabItem lang="typespec" >

Client emitters now only support a single way to represent a discriminated set in TypeSpec.

1. Use model

```typespec
@discriminator("kind")
model Cat {
  kind: string;
}

model Siamese extends Cat {
  kind: "siamese";
}

model Ragdoll extends Cat {
  kind: "ragdoll";
}
```

The type of the discriminator property could be an enum (extensible or fixed):

```typespec
@discriminator("kind")
model Cat {
  kind: CatKind;
}

union CatKind {
  string,
  Siamese: "siamese",
  Ragdoll: "ragdoll",
}

model Siamese extends Cat {
  kind: CatKind.Siamese;
}

model Ragdoll extends Cat {
  kind: CatKind.Ragdoll;
}
```

</ClientTabItem>
<ClientTabItem lang="python">

```python
from .. import _model_base
from .._model_base import rest_discriminator, rest_field

class Cat(_model_base.Model):
    kind: str = rest_discriminator(name="kind")

class Siamese(Cat):
    kind: Literal["siamese"] = rest_discriminator(name="kind")

class Ragdoll(Cat):
    kind: Literal["ragdoll"] = rest_discriminator(name="kind")
```

</ClientTabItem>
<ClientTabItem lang="csharp" >

In .Net generated code, the discriminator property will be generated as internal by default, but configurable to be public.

```csharp
public abstract partial class Cat
{
  protected Cat()
  {
  }

  internal string Kind { get; set; }
}

public partial class Siamese : Cat
{
  public Siamese() : base()
  {
    Kind = "siamese";
  }
}

public partial class Ragdoll : Cat
{
  public Ragdoll() : base()
  {
    Kind = "ragdoll";
  }
}
```

</ClientTabItem>
<ClientTabItem lang="typescript" >

```ts
// JS CodeGen models
/** model interface Cat */
export interface Cat {
  kind: string;
}

/** Alias for CatUnion */
export type CatUnion = Siamese | Ragdoll | Cat;

/** model interface Siamese */
export interface Siamese extends Cat {
  kind: "siamese";
}
/** model interface Ragdoll */
export interface Ragdoll extends Cat {
  kind: "ragdoll";
}
```

</ClientTabItem>
<ClientTabItem lang="java" >

```java
public class Cat implements JsonSerializable<Cat> {
    public Cat();
    public String getKind();
}

public final class Ragdoll extends Cat {
    public Ragdoll();
    public String getKind();
}

public final class Siamese extends Cat {
    public Siamese();
    public String getKind();
}
```

</ClientTabItem>

<ClientTabItem lang="go">

```go
// CatClassification provides polymorphic access to related types.
// Call the interface's GetCat() method to access the common type.
// Use a type switch to determine the concrete type.  The possible types are:
// - *Cat, *Ragdoll, *Siamese
type CatClassification interface {
	// GetCat returns the Cat content of the underlying type.
	GetCat() *Cat
}

type Cat struct {
	// REQUIRED
	Kind *string
}

// GetCat implements the CatClassification interface for type Cat.
func (c *Cat) GetCat() *Cat { return c }

type Ragdoll struct {
	// CONSTANT; undefinedField has constant value "ragdoll", any specified value is ignored.
	Kind *string
}

// GetCat implements the CatClassification interface for type Ragdoll.
func (e *Ragdoll) GetCat() *Cat {
	return &Cat{
		Kind:     e.Kind,
	}
}

type Siamese struct {
	// CONSTANT; undefinedField has constant value "siamese", any specified value is ignored.
	Kind *string
}

// GetCat implements the CatClassification interface for type Siamese.
func (e *Siamese) GetCat() *Cat {
	return &Cat{
		Kind:     e.Kind,
	}
}
```

</ClientTabItem>
</ClientTabs>

### Nullable

TypeSpec uses `| null` to represent nullable types. Nullability is handled differently in languages, but emitter authors will find information
about nullability by inspecting the type of a property.

<ClientTabs>
<ClientTabItem lang="typespec" >

```typespec
model Foo {
  basicNullableProperty: string | null;
  modelNullableProperty: Bar | null;
  enumNullableProperty: LR | null;
}

model Bar {
  prop: string;
}

enum LR {
  left,
  right,
}
```

</ClientTabItem>
<ClientTabItem lang="python">

Python treat nullable as optional. If you actually want to send the value `null` to the service without the property being ignored, you can send in `corehttp.serialization.NULL`. Python does not restrict you from setting any property to this value.

```python
from enum import Enum
from corehttp.utils import CaseInsensitiveEnumMeta

class Bar(_model_base.Model):
  prop: Optional[str] = rest_field()

class LR(str, Enum, metaclass=CaseInsensitiveEnumMeta):
  LEFT = "left"
  RIGHT = "right"

class Foo(_model_base.Model):
  basicNullableProperty: Optional[str] = rest_field()
  modelNullableProperty: Optional["_models.Bar"] = rest_field()
  enumNullableProperty: Optional["LR"] = rest_field()

```

</ClientTabItem>
<ClientTabItem lang="csharp" >

```csharp
namespace TestService
{
  public partial class Foo
  {
    public string BasicNullableProperty { get; }
    public Bar ModelNullableProperty { get; }
    public LR? EnumNullableProperty { get; }
  }

  public partial class Bar
  {
    public string Prop { get; }
  }

  public enum LR
  {
    Left,
    Right
  }
}
```

</ClientTabItem>
<ClientTabItem lang="typescript" >
```ts
export interface Foo {
  basicNullableProperty: string | null;
  modelNullableProperty: Bar | null;
  enumNullableProperty: LR | null;
}

export interface Bar {
  prop: string;
}

export type LR = "left" | "right";
```
</ClientTabItem>
<ClientTabItem lang="java" >

```java
// All Java reference type is nullable.
public final class Foo implements JsonSerializable<Foo> {
    public String getBasicNullableProperty();
    public Bar getModelNullableProperty();
    public LR getEnumNullableProperty();
}

public final class Bar implements JsonSerializable<Bar> {
    public String getProp();
}

public enum LR {
    LEFT("left"),
    RIGHT("right");
}
```

</ClientTabItem>
<ClientTabItem lang="go" >

```go
type Foo struct {
  BasicNullableProperty *string
  ModelNullableProperty *Bar
  EnumNullableProperty  *LR
}

type Bar struct {
  Prop *string
}

type LR string

const (
  LRLeft LR = "left"
  LRRight LR = "right"
)

```

</ClientTabItem>
</ClientTabs>

### Flattening

:::caution
Flattening is NOT a recommended pattern, and you shouldn't use it unless told by SDK architects.
:::

<ClientTabs>
<ClientTabItem lang="typespec" >

```typespec
model Properties {
  name: string;
}

model Foo {
  @flattenProperty
  prop: Properties;
}
```

</ClientTabItem>
<ClientTabItem lang="python">

Python will do dynamic flattening, exposing the non-flattening syntax, and dynamically accepting the flattened access.

```python
class Properties(_model_base.Model):
    name: str = rest_field()
    """Required."""

class Foo(_model_base.Model):
    properties: "_models.Properties" = rest_field()
    """Required."""

    __flattened_items = ["properties"]

print(f.properties.name)  # Non-flattened access is preferred experience
print(f.name)  # Flattened access is dynamically supported, but not documented

```

</ClientTabItem>
<ClientTabItem lang="csharp" >

CSharp will generate the model with properties being flattened. During serialization/deserialization, the model will be serialized/deserialized as a non-flattened model.

```csharp
public partial class Foo
{
    public Foo(string name)
    {
        Argument.AssertNotNull(name, nameof(name));

        Name = name;
    }

    public string Name { get; set; }
}

public partial class Foo : IUtf8JsonSerializable, IJsonModel<Foo>
{
    void IJsonModel<Foo>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
    {
        var format = options.Format == "W" ? ((IPersistableModel<Foo>)this).GetFormatFromOptions(options) : options.Format;
        if (format != "J")
        {
            throw new FormatException($"The model {nameof(Foo)} does not support writing '{format}' format.");
        }

        writer.WriteStartObject();
        writer.WritePropertyName("properties"u8);
        writer.WriteStartObject();
        writer.WritePropertyName("name"u8);
        writer.WriteStringValue(Name);
        writer.WriteEndObject();
        writer.WriteEndObject();
    }

    internal static Foo DeserializeFoo(JsonElement element, ModelReaderWriterOptions options = null)
    {
        options ??= ModelSerializationExtensions.WireOptions;

        if (element.ValueKind == JsonValueKind.Null)
        {
            return null;
        }
        string name = default;
        foreach (var property in element.EnumerateObject())
        {
            if (property.NameEquals("properties"u8))
            {
                if (property.Value.ValueKind == JsonValueKind.Null)
                {
                    property.ThrowNonNullablePropertyIsNull();
                    continue;
                }
                foreach (var property0 in property.Value.EnumerateObject())
                {
                    if (property0.NameEquals("name"u8))
                    {
                        name = property0.Value.GetString();
                    }
                }
            }
        }
        return new Foo(name);
    }
}
```

</ClientTabItem>
<ClientTabItem lang="typescript" >

```typescript
// This is for legacy pattern, for new services/APIs, it's not recommended.
export interface Foo {
  name: string;
}
export function _fooPropSerializer(item: Foo): any {
  return { name: item["name"] };
}

export function _fooPropDeserializer(item: any) {
  return {
    name: item["name"],
  };
}
```

</ClientTabItem>
<ClientTabItem lang="java" >

In Java, `@flattenProperty` have no effect on generated libraries.

```java
@Fluent
public final class Properties {
    public Properties();
    public String getName();
    public Properties setName(String name);
}
```

</ClientTabItem>
</ClientTabs>

### Multi-Level Inheritance (Legacy)

:::caution
Legacy multi-level inheritance is NOT a recommended pattern, and you shouldn't use it unless told by SDK architects.
:::

The `@Azure.ClientGenerator.Core.Legacy.hierarchyBuilding` decorator enables client-level multiple levels of inheritance for discriminated models. This decorator modifies the inheritance chain in generated client libraries to create deeper hierarchies than what TypeSpec natively supports.

Use `@hierarchyBuilding` when you need to represent complex inheritance hierarchies in discriminated models where:

- You have multiple levels of inheritance (grandparent → parent → child)
- You need to share common properties across multiple inheritance levels
- You have permission from SDK architects

<ClientTabs>
<ClientTabItem lang="typespec">

```typespec
@discriminator("kind")
model Animal {
  kind: string;
  name: string;
}

alias PetContent = {
  owner: string;
  vaccinated: boolean;
};

model Pet extends Animal {
  kind: "pet";
  ...PetContent;
}

@Azure.ClientGenerator.Core.Legacy.hierarchyBuilding(Pet)
model Dog extends Animal {
  kind: "dog";
  ...PetContent;
  breed: string;
}
```

</ClientTabItem>
<ClientTabItem lang="python">

```python
from enum import Enum
from typing import Optional, Literal
from .. import _model_base
from .._model_base import rest_discriminator, rest_field

class Animal(_model_base.Model):
    kind: str = rest_discriminator(name="kind")
    name: str = rest_field()

class Pet(Animal):
    kind: Literal["pet"] = rest_discriminator(name="kind")
    owner: str = rest_field()
    vaccinated: bool = rest_field()

class Dog(Pet):  # Inherits from Pet, not Animal
    kind: Literal["dog"] = rest_discriminator(name="kind")
    breed: str = rest_field()
```

</ClientTabItem>
<ClientTabItem lang="csharp">

```csharp
public abstract partial class Animal
{
    protected Animal() { }
    internal string Kind { get; set; }
    public string Name { get; set; }
}

public partial class Pet : Animal
{
    public Pet() : base()
    {
        Kind = "pet";
    }

    public string Owner { get; set; }
    public bool Vaccinated { get; set; }
}

public partial class Dog : Pet  // Inherits from Pet, not Animal
{
    public Dog() : base()
    {
        Kind = "dog";
    }

    public string Breed { get; set; }
}
```

</ClientTabItem>
<ClientTabItem lang="typescript">

```typescript
export interface Animal {
  kind: string;
  name: string;
}

export interface Pet extends Animal {
  kind: "pet";
  owner: string;
  vaccinated: boolean;
}

export interface Dog extends Pet {
  // Inherits from Pet, not Animal
  kind: "dog";
  breed: string;
}

export type AnimalUnion = Animal | Pet | Dog;
```

</ClientTabItem>
<ClientTabItem lang="java">

```java
public class Animal implements JsonSerializable<Animal> {
    public Animal();
    public String getKind();
    public String getName();
}

public final class Pet extends Animal {
    public Pet();
    public String getKind();
    public String getOwner();
    public boolean isVaccinated();
}

public final class Dog extends Pet {  // Inherits from Pet, not Animal
    public Dog();
    public String getKind();
    public String getBreed();
}
```

</ClientTabItem>
<ClientTabItem lang="go">

```go
package models

type Animal struct {
  Kind string
  Name string
}

type Pet struct {
  Animal
  Owner string
  Vaccinated bool
}

type Dog struct {
  Animal
  Owner string
  Vaccinated bool
  Breed string
}

```

</ClientTabItem>
</ClientTabs>

## Unions

### Union of literals with same type

All emitters will generate their version of a closed enum.

<ClientTabs>
<ClientTabItem lang="typespec" >

```typespec
union LR {
  left: "left",
  right: "right",
}
```

</ClientTabItem>
<ClientTabItem lang="python">

Python never generates closed enum by design. We will always permit users to pass in additional values.

```python
from enum import Enum
from corehttp.utils import CaseInsensitiveEnumMeta

class LR(str, Enum, metaclass=CaseInsensitiveEnumMeta):
  LEFT = "left"
  RIGHT = "right"
```

</ClientTabItem>
<ClientTabItem lang="csharp" >

```csharp
public enum LR
{
  Left,
  Right
}
```

Serialization/deserialization will respect the value defined, in this case it is "left" for `LR.Left` and "right" for `LR.Right` respectively.

</ClientTabItem>
<ClientTabItem lang="typescript" >

```typescript
export type LR = "left" | "right";
```

</ClientTabItem>
<ClientTabItem lang="java" >

```java
public enum LR {
   LEFT("left"),
   RIGHT("right");
}
```

</ClientTabItem>
</ClientTabs>

### Inline union of literals with same type

This is union defined inline at point of usage.

<ClientTabs>
<ClientTabItem lang="typespec" >

```typespec
model Widget {
  horizontal: "left" | "right";
}
```

</ClientTabItem>
<ClientTabItem lang="python">

Python generates this as a union of literals, not as enum. We also don't generate a closed set of literals.

```python
from typing import Literal, Union

model Widget:
  horizontal: Union[Literal["left"] | Literal["right"] | str]
```

</ClientTabItem>
<ClientTabItem lang="csharp" >

```csharp
public partial class Widget
{
  public WidgetHorizontal Horizontal;
}
public enum WidgetHorizontal
{
  Left,
  Right
}
```

</ClientTabItem>
<ClientTabItem lang="typescript" >

```typescript
export interface Widget {
  horizontal: "left" | "right";
}
```

</ClientTabItem>
<ClientTabItem lang="java" >

```java
public enum WidgetHorizontal {
   LEFT("left"),
   RIGHT("right");
}
```

</ClientTabItem>
<ClientTabItem lang="go" >

```go
package models

type Widget struct {
  Horizontal WidgetHorizontal
}

type WidgetHorizontal string

const (
  WidgetHorizontalLeft WidgetHorizontal = "left"
  WidgetHorizontalRight WidgetHorizontal = "right"
)

```

</ClientTabItem>
</ClientTabs>

### Union of basic type and literals of that type

Each language will generate their version of an open enum.

<ClientTabs>
<ClientTabItem lang="typespec" >

```typespec
union Colors {
  string,
  red: "red",
  blue: "blue",
}
```

</ClientTabItem>
<ClientTabItem lang="python">

Python generates open enum again here.

```python
from enum import Enum
from corehttp.utils import CaseInsensitiveEnumMeta

class Colors(str, Enum, metaclass=CaseInsensitiveEnumMeta):
  RED = "red"
  BLUE = "blue"
```

</ClientTabItem>
<ClientTabItem lang="csharp" >

```csharp
public readonly partial struct Colors : IEquatable<Colors>
{
  private const string RedValue = "red";
  private const string BlueValue = "blue";
  public static Colors Red { get; } = new Colors(RedValue);
  public static Colors Blue { get; } = new Colors(BlueValue);
}
```

</ClientTabItem>
<ClientTabItem lang="typescript" >

```typescript
export type Colors = string | "red" | "blue";
```

</ClientTabItem>
<ClientTabItem lang="java" >

```java
public final class Colors extends ExpandableStringEnum<Colors> {
    public static final Colors RED = fromString("red");
    public static final Colors BLUE = fromString("blue");
}
```

</ClientTabItem>
</ClientTabs>

### Inline union of basic type and literals of that type

This is union defined inline at point of usage which include the base type as an option.

<ClientTabs>
<ClientTabItem lang="typespec" >

```typespec
model Widget {
  color: "red" | "blue" | string;
}
```

</ClientTabItem>
<ClientTabItem lang="python">

Python generates a union of literals again.

```python
from typing import Literal, Union

model Widget:
  color: Union[Literal["red"] | Literal["blue"] | str]
```

</ClientTabItem>
<ClientTabItem lang="csharp" >

```csharp
public partial class Widget
{
  public WidgetColor Color;
}
public readonly partial struct WidgetColor : IEquatable<WidgetColor>
{
  private const string RedValue = "red";
  private const string BlueValue = "blue";
  public static WidgetColor Red { get; } = new WidgetColor(RedValue);
  public static WidgetColor Blue { get; } = new WidgetColor(BlueValue);
}
```

</ClientTabItem>
<ClientTabItem lang="typescript" >

```typescript
export interface Widget {
  color: "red" | "blue" | string;
}
```

</ClientTabItem>
<ClientTabItem lang="java" >

```java
public final class WidgetColor extends ExpandableStringEnum<Colors> {
    public static final Color RED = fromString("red");
    public static final Color BLUE = fromString("blue");
}
```

</ClientTabItem>
<ClientTabItem lang="go" >

```go
type Colors string

const (
  ColorsRed Colors = "red"
  ColorsBlue Colors = "blue"
)

```

</ClientTabItem>
</ClientTabs>

### Union of other union/enum, basic type and literals of that type

<ClientTabs>
<ClientTabItem lang="typespec" >

```typespec
import "@azure-tools/typespec-azure-resource-manager";

union ProvisioningState {
  string,
  "InProgress",
  Azure.ResourceManager.ResourceProvisioningState,
}
```

</ClientTabItem>
<ClientTabItem lang="python">

Python generates a single open enum.

```python
from enum import Enum
from corehttp.utils import CaseInsensitiveEnumMeta

class ProvisioningState(str, Enum, metaclass=CaseInsensitiveEnumMeta):
  INPROGRESS = "InProgress"
  SUCCEEDED = "Succeeded"
  FAILED = "Failed"
  CANCELED = "Canceled"
```

</ClientTabItem>
<ClientTabItem lang="csharp" >

```csharp
public readonly partial struct ProvisioningState : IEquatable<ProvisioningState>
{
  private const string SucceededValue = "Succeeded";
  private const string FailedValue = "Failed";
  private const string CanceledValue = "Canceled";
  private const string InProgressValue = "InProgress";

  public static ProvisioningState Succeeded { get; } = new ProvisioningState(SucceededValue);
  public static ProvisioningState Failed { get; } = new ProvisioningState(FailedValue);
  public static ProvisioningState Canceled { get; } = new ProvisioningState(CanceledValue);
  public static ProvisioningState InProgress { get; } = new ProvisioningState(InProgressValue);
}
```

</ClientTabItem>
<ClientTabItem lang="typescript" >

```typescript
export type ResourceProvisioningState = "Succeeded" | "Failed" | "Canceled";
// NOTE: extensible enum design may change in JS
export type ProvisioningState = string | "InProgress" | ResourceProvisioningState;
```

</ClientTabItem>
<ClientTabItem lang="java" >

```java
public final class ProvisioningState extends ExpandableStringEnum<ProvisioningState> {
    public static final ProvisioningState INPROGRESS = fromString("InProgress");
    public static final ProvisioningState SUCCEEDED = fromString("Succeeded");
    public static final ProvisioningState FAILED = fromString("Failed");
    public static final ProvisioningState CANCELED = fromString("Canceled");
}
```

</ClientTabItem>
<ClientTabItem lang="go" >

```go
type ProvisioningState string
const (
  ProvisioningStateInProgress ProvisioningState = "InProgress"
  // Constants from Azure.ResourceManager.ResourceProvisioningState
  ResourceProvisioningStateSucceeded ProvisioningState = "Succeeded"
  ResourceProvisioningStateFailed    ProvisioningState = "Failed"
  ResourceProvisioningStateCanceled  ProvisioningState = "Canceled"
  // ... other imported states
)

```

</ClientTabItem>
</ClientTabs>

### Union of other unions of literals with same type

<ClientTabs>
<ClientTabItem lang="typespec" >

```typespec
union LR {
  left: "left",
  right: "right",
}

union UD {
  up: "up",
  down: "down",
}

union Orientation {
  LR,
  UD,
}
```

</ClientTabItem>
<ClientTabItem lang="python">

```python
from enum import Enum
from corehttp.utils import CaseInsensitiveEnumMeta

class Orientation(str, Enum, metaclass=CaseInsensitiveEnumMeta):
  LEFT = "left"
  RIGHT = "right"
  UP = "up"
  DOWN = "down"
```

</ClientTabItem>
<ClientTabItem lang="csharp" >

```csharp
public enum Orientation
{
  Left,
  Right,
  Up,
  Down
}
```

</ClientTabItem>
<ClientTabItem lang="typescript" >

```typescript
export type LR = "left" | "right";
export type UD = "up" | "down";
export type Orientation = LR | UD;
```

</ClientTabItem>
<ClientTabItem lang="java" >

```java
public enum Orientation {
   LEFT("left"),
   RIGHT("right"),
   UP("up"),
   DOWN("down");
}
```

</ClientTabItem>
<ClientTabItem lang="go" >

```go
type Orientation string

const (
  OrientationLeft Orientation = "left"
  OrientationRight Orientation = "right"
  OrientationUp Orientation = "up"
  OrientationDown Orientation = "down"
)

```

</ClientTabItem>
</ClientTabs>

### Inline union of other unions of literals with same type

<ClientTabs>
<ClientTabItem lang="typespec" >

```typespec
union LR {
  left: "left",
  right: "right",
}

union UD {
  up: "up",
  down: "down",
}

model Widget {
  orientation: LR | UD;
}
```

</ClientTabItem>
<ClientTabItem lang="python">

Since this is inline, Python will generate this as a single union of all possible literal values.

```python
from typing import Literal

type WidgetOrientation = "left" | "right" | "up" | "down" | str

model Widget:
  orientation: WidgetOrientation
```

</ClientTabItem>
<ClientTabItem lang="csharp" >

```csharp
public partial class Widget
{
  public WidgetOrientation Orientation;
}
public enum WidgetOrientation
{
  Left,
  Right,
  Up,
  Down
}
```

</ClientTabItem>
<ClientTabItem lang="typescript" >

```typescript
export interface Widget {
  orientation: LR | UD;
}

export type LR = "left" | "right";
export type UD = "up" | "down";
```

</ClientTabItem>
<ClientTabItem lang="java" >

```java
public enum WidgetOrientation {
   LEFT("left"),
   RIGHT("right"),
   UP("up"),
   DOWN("down");
}
```

</ClientTabItem>
<ClientTabItem lang="go" >

```go
type Orientation string

const (
  OrientationLeft Orientation = "left"
  OrientationRight Orientation = "right"
  OrientationUp Orientation = "up"
  OrientationDown Orientation = "down"
)

type Widget struct {
  Orientation Orientation `json:"orientation"`
}

```

</ClientTabItem>
</ClientTabs>

## Enums

### Standard

Standard enums will be generated as closed enums.

<ClientTabs>
<ClientTabItem lang="typespec" >

```typespec
enum LR {
  left,
  right,
}
```

</ClientTabItem>
<ClientTabItem lang="python">

Python never generates closed enums by design. We will always permit users to pass in additional values.

```python
from enum import Enum
from corehttp.utils import CaseInsensitiveEnumMeta

class LR(str, Enum, metaclass=CaseInsensitiveEnumMeta):
  LEFT = "left"
  RIGHT = "right"
```

</ClientTabItem>
<ClientTabItem lang="csharp" >

```csharp
public enum LR
{
  Left,
  Right
}
```

</ClientTabItem>
<ClientTabItem lang="typescript" >

```typescript
export type LR = "left" | "right";
```

</ClientTabItem>
<ClientTabItem lang="java" >

```java
public enum LR {
   LEFT("left"),
   RIGHT("right");
}
```

</ClientTabItem>
<ClientTabItem lang="go" >

```go
type LR string

const (
  LRLeft LR = "left"
  LRRight LR = "right"
)

```

</ClientTabItem>
</ClientTabs>

### Versioning Enums

<ClientTabs>
<ClientTabItem lang="typespec" >

```typespec
@versioned(Versions)
@service
namespace Service;

enum Versions {
  v1,
  v2,
}
```

</ClientTabItem>
<ClientTabItem lang="python">

```
# Python does not generate the enum used for versioning
```

</ClientTabItem>
<ClientTabItem lang="csharp" >

```csharp
// CSharp does not generate the enum used for versioning
```

</ClientTabItem>
<ClientTabItem lang="typescript" >

```typescript
export enum KnownVersions {
  V1 = "v1",
  V2 = "v2",
}

export type Versions = string;
```

</ClientTabItem>
<ClientTabItem lang="java" >

```java
public enum ServiceServiceVersion implements ServiceVersion {
    V1("v1"),
    V2("v2");
}
```

</ClientTabItem>
<ClientTabItem lang="go" >

```go
type Versions string

const (
  VersionsV1 Versions = "v1"
  VersionsV2 Versions = "v2"
)

```

</ClientTabItem>
</ClientTabs>

### Spread

Spreading enums will return the resultant enum as a new single closed enum.

<ClientTabs>
<ClientTabItem lang="typespec" >

```typespec
enum LR {
  left,
  right,
}

enum UD {
  up,
  down,
}

enum Orientation {
  ...LR,
  ...UD,
}
```

</ClientTabItem>
<ClientTabItem lang="python">

Python generates one open enum, because Python never generates an enum as fully closed.

```python
from enum import Enum
from corehttp.utils import CaseInsensitiveEnumMeta

class Orientation(str, Enum, metaclass=CaseInsensitiveEnumMeta):
  LEFT = "left"
  RIGHT = "right"
  UP = "up"
  DOWN = "down"
```

</ClientTabItem>
<ClientTabItem lang="csharp" >

```csharp
public enum Orientation
{
  Left,
  Right,
  Up,
  Down
}
```

</ClientTabItem>
<ClientTabItem lang="typescript" >

```typescript
export type Orientation = "left" | "right" | "up" | "down";
```

</ClientTabItem>
<ClientTabItem lang="java" >

```java
public enum Orientation {
   LEFT("left"),
   RIGHT("right"),
   UP("up"),
   DOWN("down");
}
```

</ClientTabItem>
<ClientTabItem lang="go" >

```go
type LR string

const (
  LRLeft LR = "left"
  LRRight LR = "right"
)

type UD string

const (
  UDUp UD = "up"
  UDDown UD = "down"
)

type Orientation string

const (
  OrientationLeft Orientation = "left"
  OrientationRight Orientation = "right"
  OrientationUp Orientation = "up"
  OrientationDown Orientation = "down"
)

```

</ClientTabItem>
</ClientTabs>

## Scalars

### Encoding

We will take the `@encode` decorator into account, determining how we serialize inputted scalars to send over the wire.

<ClientTabs>
<ClientTabItem lang="typespec" >

```typespec
model Test {
  @encode(DateTimeKnownEncoding.rfc3339)
  prop: utcDateTime;
}
```

</ClientTabItem>
<ClientTabItem lang="python">

```python
serialized_prop = json.dumps(prop, cls=SdkJSONEncoder, format="rfc3339")
```

</ClientTabItem>
<ClientTabItem lang="csharp" >

```csharp
// Internal implementation
utf8JsonWriter.WriteStringValue(Prop.ToString());
```

</ClientTabItem>
<ClientTabItem lang="typescript" >

```typescript
export interface Test {
  prop: Date;
}

export function testSerializer(item: Test): any {
  return { prop: item["prop"].toISOString() };
}

export function testDeserializer(item: any): Test {
  return {
    prop: new Date(item["prop"]),
  };
}
```

</ClientTabItem>
<ClientTabItem lang="java" >

```java
// Internal implementation
jsonWriter.writeStringField("prop",
    this.value == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.value));
```

</ClientTabItem>
</ClientTabs>

When you specify an encoding type, say that you want to encode an integer as a string, that will also be represented in our generated SDKs.

<ClientTabs>
<ClientTabItem lang="typespec" >

```typespec
model Test {
  @encode(string)
  prop: int64;
}
```

</ClientTabItem>
<ClientTabItem lang="python">

```python
serialized_prop = json.dumps(prop, cls=SdkJSONEncoder, format="string")
```

</ClientTabItem>
<ClientTabItem lang="csharp" >

```csharp
// The property is exposed as `long`; serialization writes it as a JSON string.
namespace TestService
{
  public partial class Test
  {
    public long Prop { get; }
  }
}

// Internal implementation
writer.WriteStringValue(Prop.ToString());
```

</ClientTabItem>

<ClientTabItem lang="typescript" >

```typescript
export interface Test {
  prop: string;
}

export function testSerializer(item: Test): any {
  return { prop: item["prop"] };
}

export function testDeserializer(item: any): Test {
  return {
    prop: item["prop"],
  };
}
```

</ClientTabItem>
<ClientTabItem lang="java" >

```java
// Internal implementation
jsonWriter.writeStringField("prop", Objects.toString(this.value, null));
```

</ClientTabItem>
<ClientTabItem lang="go" >

```go
type Test struct {
    // REQUIRED
    Prop *int64
}

// Custom MarshalJSON converts int64 to a JSON string.
func (t Test) MarshalJSON() ([]byte, error) {
    objectMap := make(map[string]any)
    populate(objectMap, "prop", to.Ptr(strconv.FormatInt(*t.Prop, 10)))
    return json.Marshal(objectMap)
}
```

</ClientTabItem>
</ClientTabs>
