← Back to blog
Payments12 min read

ISO 20022 Structured Address: pain.001 Spring Boot Guide

Unstructured AdrLine-only addresses risk rejection from November 2026. Build a Spring Boot pain.001 normalizer with hybrid fallback and validation.

Illustration of a free-text postal address being split into labelled structured fields like street name, building number, post code, town and country, then passing through a validation gate before reaching a payment message

An ISO 20022 structured address splits a postal address into named fields (StrtNm, BldgNb, PstCd, TwnNm, Ctry) instead of free-text AdrLine entries. From November 2026, a pain.001 payment needs at least town and country in their own fields (a hybrid address) or it can be refused. In Spring Boot, the fix is an address normalizer that scores its confidence and falls back to hybrid when the score is low.

Look at your own customer table before you read further. If the address lives in one VARCHAR(255) with commas in it, which is how many legacy payment systems store it, there is no town column to query and nothing structured to put in the XML. That was the starting point for the design below, and the rest of this post covers the rule, the conversion code in Spring Boot, and a rollout that does not put live payments at risk.

Where the date stands

Swift's published position is that from 14 November 2026, CBPR+ payment messages must carry at least town and country in their own fields, and fully unstructured addresses are expected to be refused at network level. Bank and SEPA scheme guidance I have read points at the same month. If you are also preparing for January 2027, my SEPA Instant blueprint for non-euro PSPs covers the receive-side work that lands in the same quarter.

One caveat: Swift announced a change to its SR2026 timeline in August 2026, and the wording mentions a community request to extend structured-address migration. I could not confirm the revised date or scope from the pages I could reach. My decision rule is simple. Treat hybrid as the floor today, because that is the least any bank will accept under either reading, and treat full structure as a data-quality goal you phase in per country. Then read Swift's current SR2026 notes and your own bank's fact sheet to learn whether refusals are already live for your corridors. The code is identical in both cases, and your bank can start rejecting on its own schedule regardless of the network date.

Part 1: What the three address shapes look like

A payment message names the payer and the payee, and each party can carry a postal address. In ISO 20022, the XML standard that replaced formats such as MT103, that element is PstlAdr. There are three ways to fill it.

  1. Unstructured. Only AdrLine elements, each a line of free text. Example: AdrLine: "12 Rue de la Paix, 75002 Paris, France". A person reads it fine. A machine must guess where the street ends and the town begins.
  2. Structured. Named fields: StrtNm (street name), BldgNb (building number), PstCd (post code), TwnNm (town name), Ctry (country, as a two-letter code like FR). A fully structured address must not also carry AdrLine. Mixing the two is a mistake that bank pre-checks catch, and Deutsche Bank's fact sheet spells the rule out.
  3. Hybrid. TwnNm and Ctry are required, and up to two AdrLine entries carry whatever else you have. Under the PMPG hybrid guidance published through Swift, structured data wins if it conflicts with the lines.

The textbook example hides the cases that actually break parsers. Here are the ones I would test before trusting any splitter:

  • Multi-line German addresses. Musterstraße 12a followed by c/o Schmidt followed by 80331 München. The c/o line fits neither the street nor the town. Hausnummer suffixes (12a, 12-14, 12 1/2) must stay inside BldgNb, not leak into the street.
  • Care-of and PO box lines. Postfach 1234 or PO Box 77 is not a street. Putting it in StrtNm is a wrong structured address, so it belongs in an AdrLine under hybrid.
  • Number-first versus number-last. French and UK addresses lead with the number; German, Dutch and Nordic addresses end with it. A single regex cannot serve both.
  • Postcode before or after the town. 75002 Paris in France, Paris 75002 nowhere you want to guess, and London SW1A 1AA where the postcode is two tokens.
  • Countries with no postcode. Ireland only recently gained Eircodes; several Gulf states have none. A parser that requires PstCd will fail valid addresses.
  • Non-Latin and reversed-order addresses. Japanese addresses run from prefecture down to building, Indian addresses often name a landmark before the street. Rules written for Western order will produce confident nonsense here, which is the strongest argument for hybrid as the default outside your core markets.

Banks care because sanctions screening compares names and places against watch lists. When the town sits inside a text line, the screening engine must parse it first, and parse errors turn into false alerts or missed matches. Payee-name checks have the same weakness, and I dealt with them in the IBAN-name verification and fraud-liability engine post. The new rule pushes the cleanup to whoever creates the message, which means you.

It lands on backend teams for a structural reason: the requirement flows upstream. A bank forwards pacs.008 (the interbank credit transfer) across the network, but the content originates in pain.001, the initiation message your system sends to your bank. If your pain.001 carries no town, the bank has nothing to forward.

A minimal hybrid creditor address in pain.001.001.09 looks like this:

<Cdtr>
  <Nm>Maison Lefevre SARL</Nm>
  <PstlAdr>
    <TwnNm>Paris</TwnNm>
    <Ctry>FR</Ctry>
    <AdrLine>12 Rue de la Paix</AdrLine>
    <AdrLine>75002</AdrLine>
  </PstlAdr>
</Cdtr>

And the fully structured version of the same party:

<PstlAdr>
  <StrtNm>Rue de la Paix</StrtNm>
  <BldgNb>12</BldgNb>
  <PstCd>75002</PstCd>
  <TwnNm>Paris</TwnNm>
  <Ctry>FR</Ctry>
</PstlAdr>

Part 2: Four components and a rollout switch

I split the work into four components and one feature flag instead of writing a single converter. The reason is failure isolation. Parsing is probabilistic, format choice is a policy decision, validation is deterministic, and rejection handling is asynchronous. Each changes for a different reason and fails in a different way. A converter that mixes them cannot be tested by feeding it a bad address and watching one thing go wrong.

  • AddressNormalizer turns legacy free text into structured fields plus a confidence score.
  • AddressFormatSelector applies policy: structured, hybrid, or send to repair.
  • PreSubmissionValidator checks the finished XML against the XSD and the business rules. I wrote a standalone version of this piece in the ISO 20022 structured address validator post.
  • AddressRejectHandler takes bank and scheme rejections and queues them for repair. Repair events go out through a transactional outbox, so a rejection is neither lost nor handled twice.

One rule drives the whole design: a wrong structured address is worse than a correct hybrid one. Hybrid is compliant. A confidently wrong StrtNm is a data-quality defect that sanctions and payee-matching systems will then take as fact.

Part 3: The schema first

You need somewhere to store the structured parts before any parser runs. I add columns next to the legacy line and leave the old one alone, following the expand-and-contract approach from my zero-downtime Flyway migrations post. The old column goes away only after every reader has moved.

-- V42__customer_address_structured.sql
ALTER TABLE customer_address
    ADD COLUMN street_name      VARCHAR(70),
    ADD COLUMN building_number  VARCHAR(16),
    ADD COLUMN post_code        VARCHAR(16),
    ADD COLUMN town_name        VARCHAR(35),
    ADD COLUMN country_code     CHAR(2),
    ADD COLUMN address_format   VARCHAR(12) NOT NULL DEFAULT 'UNSTRUCTURED',
    ADD COLUMN parse_confidence NUMERIC(4,3),
    ADD COLUMN parsed_at        TIMESTAMPTZ,
    ADD COLUMN needs_repair     BOOLEAN NOT NULL DEFAULT FALSE;

ALTER TABLE customer_address
    ADD CONSTRAINT chk_address_format
    CHECK (address_format IN ('STRUCTURED','HYBRID','UNSTRUCTURED'));

ALTER TABLE customer_address
    ADD CONSTRAINT chk_country_iso
    CHECK (country_code IS NULL OR country_code ~ '^[A-Z]{2}$');

CREATE INDEX CONCURRENTLY idx_address_repair
    ON customer_address (needs_repair) WHERE needs_repair;

The column sizes come from the schema: ISO 20022 limits TwnNm to 35 characters, StrtNm to 70, and PstCd and BldgNb to 16. Enforcing them at the database means an oversized value fails when you write it, not later inside a bank's rejection file. One practical catch: CREATE INDEX CONCURRENTLY cannot run inside a transaction, so on PostgreSQL give it its own migration with Flyway's executeInTransaction=false.

Part 4: The normalizer with a confidence score

For address parsing, open-source libpostal is the common choice, and the top-ranking Medium article on this topic calls it from Python. On the JVM you have three realistic routes: a libpostal sidecar over HTTP, JNI bindings, or hand-written rules for the countries you serve. My split is rules for the biggest markets and a sidecar for the long tail, since a rule can be explained to an auditor who asks why a given street was cut where it was.

Here is the rule-based core for one common European shape, "street and number, post code and town, country":

public record ParsedAddress(
        String streetName, String buildingNumber, String postCode,
        String townName, String countryCode, double confidence) {}

@Component
public class AddressNormalizer {

    private static final Pattern STREET_FIRST = Pattern.compile(
        "^(?<bn>\\d{1,5}[A-Za-z]?)\\s+(?<st>[^,]{3,70})$");
    private static final Pattern STREET_LAST = Pattern.compile(
        "^(?<st>[^,\\d]{3,70})\\s+(?<bn>\\d{1,5}[A-Za-z]?)$");
    private static final Pattern POST_TOWN = Pattern.compile(
        "^(?<pc>[A-Z0-9][A-Z0-9 \\-]{2,9}?)\\s+(?<tn>\\p{L}[\\p{L} .'\\-]{1,34})$");

    private final CountryRegistry countries;   // name/alias -> ISO alpha-2

    public AddressNormalizer(CountryRegistry countries) {
        this.countries = countries;
    }

    public ParsedAddress normalize(List<String> lines, String fallbackCountry) {
        List<String> parts = lines.stream()
            .flatMap(l -> Arrays.stream(l.split(",")))
            .map(String::trim).filter(s -> !s.isBlank()).toList();

        double score = 0.0;
        String country = null, street = null, bn = null, pc = null, town = null;

        // country: last token, or the party's known country
        if (!parts.isEmpty()) {
            Optional<String> c = countries.resolve(parts.get(parts.size() - 1));
            if (c.isPresent()) { country = c.get(); parts = parts.subList(0, parts.size() - 1); score += 0.30; }
        }
        if (country == null && fallbackCountry != null) { country = fallbackCountry; score += 0.10; }

        for (String p : parts) {
            Matcher pt = POST_TOWN.matcher(p);
            if (town == null && pt.matches()) {
                pc = pt.group("pc").trim(); town = pt.group("tn").trim(); score += 0.35; continue;
            }
            Matcher a = STREET_FIRST.matcher(p);
            Matcher b = STREET_LAST.matcher(p);
            if (street == null && a.matches()) { bn = a.group("bn"); street = a.group("st"); score += 0.30; }
            else if (street == null && b.matches()) { bn = b.group("bn"); street = b.group("st"); score += 0.30; }
        }
        // ambiguity penalty: leftover tokens we could not place
        long unplaced = parts.stream().filter(p ->
            !p.equals(town == null ? "" : pc + " " + town)
            && !p.contains(street == null ? "\u0000" : street)).count();
        score -= 0.15 * unplaced;

        return new ParsedAddress(street, bn, pc, town, country, Math.max(0, Math.min(1, score)));
    }
}

The score is crude on purpose. What matters is that it is monotonic: every piece you place with a pattern raises it, and every leftover token you could not place lowers it. That gives the selector something to compare against a threshold. The weights above are my starting guesses, not measured values, and they are the part you must not copy blindly.

Calibration is where this gets hard. A score of 0.8 only means something if roughly 80 percent of addresses scoring 0.8 are actually right, and a hand-weighted sum gives no such guarantee. I would not set the threshold from intuition. Take a sample of addresses that operations staff have already corrected by hand, run the normalizer over them, and plot score against the share that matched the human answer. Pick the threshold where the wrong-split rate is lower than you are willing to tolerate in sanctions data, and do it per country, since a score that is trustworthy for French addresses can be nonsense for Japanese ones. I have no benchmark numbers to hand you for libpostal on non-Latin or non-US input. Published accuracy figures come from its own training data, so measure on yours.

Part 5: Choosing structured, hybrid or repair

The selector is deliberately boring. It reads the parse result and applies a policy, nothing else:

public enum AddressFormat { STRUCTURED, HYBRID, REPAIR }

@Component
public class AddressFormatSelector {

    private final double structuredThreshold;
    private final double hybridThreshold;

    public AddressFormatSelector(
            @Value("${address.threshold.structured:0.85}") double structuredThreshold,
            @Value("${address.threshold.hybrid:0.40}") double hybridThreshold) {
        this.structuredThreshold = structuredThreshold;
        this.hybridThreshold = hybridThreshold;
    }

    public AddressFormat select(ParsedAddress p) {
        boolean hasTownAndCountry = p.townName() != null && p.countryCode() != null;
        if (!hasTownAndCountry || p.confidence() < hybridThreshold) {
            return AddressFormat.REPAIR;            // cannot even satisfy the hybrid floor
        }
        boolean fullyPlaced = p.streetName() != null && p.postCode() != null;
        if (fullyPlaced && p.confidence() >= structuredThreshold) {
            return AddressFormat.STRUCTURED;
        }
        return AddressFormat.HYBRID;                // safe middle step
    }
}

Two details matter. First, REPAIR triggers on a missing town or country, not only on a low score, because those two fields are the hybrid floor and no amount of confidence replaces them. Second, thresholds come from configuration so you can tighten them per environment without a redeploy. Parties that land in REPAIR get needs_repair = true and show up in the repair queue, and their payments keep flowing only if you still have a legitimate hybrid path for them.

Part 6: Emitting the XML

The writer branches on the selected format. For hybrid it puts the free text into at most two AdrLine elements and never mixes structured street fields into the same block:

void writeAddress(XMLStreamWriter w, PartyAddress a, AddressFormat fmt) throws XMLStreamException {
    w.writeStartElement("PstlAdr");
    if (fmt == AddressFormat.STRUCTURED) {
        element(w, "StrtNm", a.streetName());
        element(w, "BldgNb", a.buildingNumber());
        element(w, "PstCd", a.postCode());
        element(w, "TwnNm", a.townName());
        element(w, "Ctry", a.countryCode());
    } else { // HYBRID
        element(w, "TwnNm", a.townName());
        element(w, "Ctry", a.countryCode());
        List<String> rest = a.remainingLines();           // street, c/o, PO box, post code
        for (String line : rest.subList(0, Math.min(2, rest.size()))) {
            element(w, "AdrLine", truncate(line, 70));
        }
    }
    w.writeEndElement();
}

If you have more than two leftover lines, merge them in a defined order (street first, then c/o or box, then post code) instead of silently dropping data. Truncation to 70 characters is the AdrLine limit, and the validator should flag any line that had to be cut.

Part 7: Rejections and the repair loop

Even good validation does not stop every refusal, since banks apply their own pre-checks. The reject handler maps a bank's reason code to a repair action, writes an outbox event, and flips needs_repair. It must be idempotent, because bank status files get redelivered:

@Transactional
public void onRejection(PaymentRejected evt) {
    if (processed.existsByMessageId(evt.messageId())) return;   // redelivered file
    addresses.markNeedsRepair(evt.partyId(), evt.reasonCode());
    outbox.publish(new AddressRepairRequested(evt.partyId(), evt.reasonCode()));
    processed.save(evt.messageId());
}

I keep the reason code on the record so that after a few weeks you can see whether refusals cluster on one country, one bank or one parsing rule, and fix the cause instead of the individual payments.

Rollout order that keeps live payments safe

  1. Ship the migration and the new columns. Nothing reads them yet.
  2. Run the normalizer in shadow mode as a batch job over existing customers, writing results to the new columns but still sending the old format. Review the score distribution and a hand-checked sample per country.
  3. Turn on hybrid for every party that has a town and country. This is the compliance floor and the cheapest win.
  4. Enable full structure only for countries where the sampled wrong-split rate is acceptable, behind a per-country flag.
  5. Work the repair queue down. Leave the legacy column in place until every reader has stopped using it, then drop it in a later migration.

FAQ

What is a structured postal address in ISO 20022? An address split into named fields (street name, building number, post code, town, country) rather than free-text lines.

What is a hybrid postal address? Town and country as separate fields, plus up to two free-text lines for the rest. It is the fallback for addresses you cannot split with confidence.

Why are unstructured addresses being rejected? Screening and payee-matching systems handle free text poorly, so the industry requires at least town and country to be machine-readable.

Do I need to change my backend or only the bank file? The backend. The file is generated from stored data, and free-text-only records contain nothing structured to emit.

Can I guess the fields from free text? Only with a measured confidence score and a hybrid fallback. A wrong structured address is worse than a correct hybrid one.