Skip to main content

Default Values

Null Default

When the smithy.api#default trait annotating a shape contains a null value, and the shape is not additionally annotated explicitly as nullable, Smithy4s will (where possible) assume a "zero value" as the default. For example:

structure Test {
@default // same thing as @default(null)
one: String
}

Here the default for the field one will be assumed to be an empty string (""). Below is a table showing what all the zero values are for each different Smithy shape type:

Smithy TypeZero Value
blobArray.empty
booleanfalse
string""
byte0
short0
integer0
long0
float0
double0
bigInteger0
bigDecimal0
timestamp0 epoch (01 Jan 1970)
documentDocument.DNull
enumN/A
intEnumN/A
listList.empty
mapMap.empty
structureN/A
unionN/A
serviceN/A
operationN/A
resourceN/A

Not every shape type has a corresponding zero value. For example, there is no reasonable zero value for a structure or a union type. As such, they will not have a zero value set even if they are marked with a null default trait.