# `PostalAddress`

A postal address in any country: its street lines, its locality, region and postal code where its country uses them, and the country. It has no single text form; `text.format` writes it in its country's order for the reader. Personal data.

[People and contact](types.md#people-and-contact); not ordered; since Jadpo 0.1.0.

## Make one

Build one from its fields, `PostalAddress { lines: ...  country: ... }`.

Its parts keep these rules; a value that breaks one fails with the rule's name:

- `postal_code_of_country`: `postal_code is in the form of its country's postal codes`

## Fields

| Field | Type |
|---|---|
| `lines` | `List<Text>` |
| `locality` | `Text?` |
| `region` | `Text?` |
| `postal_code` | [`PostalCode`](type-postal-code.md)`?` |
| `country` | [`Country`](type-country.md) |

## Text, JSON and storage

It has no single text form, so `text.from` and `text.parse` don't take it. JSON sends an object of its parts.

| JSON |
|---|
| `{"lines":["Buckingham Palace"],"locality":"London","region":null,"postal_code":"SW1A 1AA","country":"GB"}` |
| `{"lines":["2-7-2 Marunouchi"],"locality":"Chiyoda-ku","region":"Tokyo","postal_code":"100-8994","country":"JP"}` |

It is stored in 5 columns, each named for the field, `_` and its suffix. This is `{"lines":["2-7-2 Marunouchi"],"locality":"Chiyoda-ku","region":"Tokyo","postal_code":"100-8994","country":"JP"}`:

| Column | Type | Holds |
|---|---|---|
| `<field>_lines` | `text[]` | `ARRAY['2-7-2 Marunouchi']::text[]` |
| `<field>_locality` | `text` | `'Chiyoda-ku'` |
| `<field>_region` | `text` | `'Tokyo'` |
| `<field>_postal_code` | `text` | `'100-8994'` |
| `<field>_country` | `text` | `'JP'` |

## Shown to people

`text.format(value, locale:)` shows it to people in their locale.

With `locale: Locale.en_gb`:

| Value | Shown |
|---|---|
| `{"lines":["Buckingham Palace"],"locality":"London","region":null,"postal_code":"SW1A 1AA","country":"GB"}` | `"Buckingham Palace\nLondon\nSW1A 1AA"` |
| `{"lines":["2-7-2 Marunouchi"],"locality":"Chiyoda-ku","region":"Tokyo","postal_code":"100-8994","country":"JP"}` | `"2-7-2 Marunouchi\nChiyoda-ku, Tokyo\n100-8994\nJapan"` |

## Operations

It has the contract's own operations: `text.format`, `json.read`, `json.write` and `==`. It isn't ordered, so `<` and sorting don't take it. [Every standard type meets one contract](../topics/every-standard-type-meets-one-contract.md) says how they work.
