# `Spectral.Codec.String`
[🔗](https://github.com/andreashasse/spectral/blob/main/lib/spectral/codec/string.ex#L1)

Built-in codec for `String.t()`.

Validates that encoded and decoded values are UTF-8 binaries, and optionally
enforces constraints supplied via `type_parameters` in a `spectral` annotation
placed before the type definition:

- `min_length` — minimum codepoint length (inclusive)
- `max_length` — maximum codepoint length (inclusive)
- `pattern` — regular expression the string must match

When no params are present the codec acts as a transparent pass-through,
accepting any binary and producing it unchanged.

Note: `type_parameters` are only accessible when the codec is invoked directly
from a `Spectral` entry point (e.g. `Spectral.encode/decode` called with the
type's own module). They are not propagated during mid-traversal dispatch.

## Registration

Registered automatically when the `:spectral` application starts. To use a
different codec for `String.t()`, set it in `config :spectra, :codecs`;
user-configured codecs take precedence over the built-ins.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
