Skip to content

feat: configurable encoding with legacy 1.0.x compatibility mode#22

Open
mariuszs wants to merge 2 commits into
masterfrom
feat/configurable-encoding
Open

feat: configurable encoding with legacy 1.0.x compatibility mode#22
mariuszs wants to merge 2 commits into
masterfrom
feat/configurable-encoding

Conversation

@mariuszs

Copy link
Copy Markdown
Member

Version 1.1.0 switched the UUID pairing algorithm (ElegantPairing → BigIntegerPairing), silently changing every generated FriendlyId — and old identifiers decode to a different UUID without any error. Services still on 1.0.x whose identifiers are persisted by external consumers (e.g. a public API) could never upgrade past 1.0.4 without breaking their published ID space.

This makes the encoding selectable while keeping the current behaviour as the default:

  • New public enum FriendlyIdEncoding:
    • STANDARD — bit-shifting pairing, wire-compatible with 1.1.0+, default
    • LEGACY — Szudzik's elegant pairing, wire-compatible with 1.0.x (restored ElegantPairing)
  • Global selection via FriendlyIds.setEncoding(...) — every integration module (Jackson 3, Jackson 2, JPA, jOOQ, OpenFeign, Spring) funnels through FriendlyIds/Url62, so the setting applies everywhere
  • Spring Boot starter property: com.devskiller.friendly-id.encoding=legacy (new FriendlyIdProperties bound in FriendlyIdAutoConfiguration, plus first tests for the starter)
  • Wire format pinned by vectors generated from the released 1.0.4 and 1.1.0/2.0.0-beta5 artifacts, including edge cases (zero UUID, all-bits UUID, LSB sign bit)
  • README migration-guide section + CHANGELOG entry

Full build: 7101 tests, 0 failures.

Motivation: lets 1.0.x-era services adopt 2.0 (Spring Boot 4 / Jackson 3) with legacy encoding, while 1.1.0+ services upgrade with no changes.

mariuszs added 2 commits July 17, 2026 15:38
Version 1.1.0 switched the UUID pairing algorithm from Szudzik's elegant
pairing to bit-shifting BigIntegerPairing, silently changing every generated
FriendlyId and making old identifiers decode to wrong UUIDs. Services still
on 1.0.x (with identifiers persisted by external consumers) could never
upgrade without breaking their public ID space.

- new public enum FriendlyIdEncoding: STANDARD (default, 1.1.0+ compatible)
  and LEGACY (1.0.x compatible, restored ElegantPairing)
- global selection via FriendlyIds.setEncoding(...); all modules (Jackson,
  Jackson2, JPA, jOOQ, OpenFeign, Spring) funnel through it
- Spring Boot starter property: com.devskiller.friendly-id.encoding=legacy
  (new FriendlyIdProperties, bound in FriendlyIdAutoConfiguration)
- wire-format pinned by test vectors generated from released 1.0.4 and
  1.1.0/2.0.0-beta5 artifacts, incl. edge cases (zero UUID, all-bits UUID,
  lsb sign bit)
Hide implicit public constructor (java:S1118) and use BigInteger.TWO
instead of the string constructor (java:S2129).
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant