By default, Smithy does not distinguish between a missing field and a field explicitly set to null. To enable this distinction (e.g., for implementing merge patch semantics), use the @alloy#nullable trait on structure members.
In the generated Scala code, this results in a type of Option[Nullable[A]]:
None: The field is absent.Some(Nullable.Null): The field is explicitly set to null.Some(Nullable.Value(a)): The field has a specific value a.
To convert between Option and Nullable, use Nullable.fromOption(option) and nullable.toOption.
namespace example
use alloy#nullable
structure Foo {
@nullable
a: Integer
}
// Resulting Scala type:
// final case class Foo(a: Option[Nullable[Int]] = None)
// Usage:
// Foo(None) => Absence of value
// Foo(Some(Nullable.Null)) => Explicit null
// Foo(Some(Nullable.Value(1))) => Explicit value