Quick revision
The short answer
I would define shared value types, such as Money, a business date and each kind of identifier, each with one canonical text form, for example 12.50 EUR or a decimal amount plus an ISO 4217 code, ISO 8601 dates and UTC instants, and one fixed identifier format. A shared library provides the types together with their Spring converters and formatters, Jackson serializers and persistence mappings, and the same forms are used in APIs, messages and configuration. Because many services depend on that library, it is versioned carefully with backward-compatible changes, and the types are reviewed whenever a new domain is added.
What to remember
In this answer, we traced data errors between systems to differing conversion rules for money, dates and identifiers, and fixed the cause by defining shared value types with one canonical text form each. A shared library delivers them with Spring converters and formatters, Jackson and persistence adapters, the same forms are used in APIs, messages and configuration, the library is versioned carefully because so many services depend on it, and the types are reviewed when new domains are added.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would define shared value types, such as Money, a business date and each kind of identifier, each with one canonical text form, for example 12.50 EUR or a decimal amount plus an ISO 4217 code, ISO 8601 dates and UTC instants, and one fixed identifier format. A shared library provides the types together with their Spring converters and formatters, Jackson serializers and persistence mappings, and the same forms are used in APIs, messages and configuration. Because many services depend on that library, it is versioned carefully with backward-compatible changes, and the types are reviewed whenever a new domain is added.
Why this question is asked
Data errors between systems are rarely dramatic. A price of 12.5 becomes 1250 because one service sends minor units and another reads major units, a date shifts by a day because one side serialises midnight in local time, an order id loses its leading zeros in a spreadsheet export. Each service converts values correctly by its own rules; the rules simply differ. Interviewers ask this at the principal level to see whether we can fix the cause, the lack of shared definitions, rather than each symptom. In this answer, we will see why these errors happen, define canonical value types, deliver them as a shared library, apply them across APIs, messages and configuration, and keep the library healthy over the years.
1Why Conversion Rules Drift Apart
Every service has to turn values into text and back: in JSON, in Kafka messages, in CSV exports, in configuration. When there is no shared definition, each team chooses: one sends money as a double, another as a string with two decimals, a third as an integer number of cents. Dates come as 2024-03-01, 01/03/2024 or an epoch number. All of them work inside one service and fail at the boundaries.
The deeper cause is that these values are passed around as primitives, a BigDecimal or a String, so the meaning lives only in people's heads. A value type, a small class such as Money that holds the amount and the currency together and knows its own text form, puts the meaning into the code.
2Defining Canonical Value Types
For each important kind of value we choose one canonical text form, the single form every system writes. Readers may be lenient for a while during migration, but writers always produce the canonical form. The table shows the kind of decisions this involves.
| Value | Canonical form | Reason |
|---|---|---|
| Money | {"amount":"12.50","currency":"EUR"} | decimal string, never a float; ISO 4217 code |
| Business date | 2024-03-01 (ISO 8601 date) | no time zone, no shifting |
| Point in time | 2024-03-01T09:30:00Z (UTC instant) | one zone for all systems |
| Time zone | Europe/Berlin (IANA id) | offsets change with daylight saving |
| Order identifier | ord_01HV3K9Q2X (prefix + id) | self-describing, no leading-zero loss |
| Percentage | "0.075" as a decimal fraction | no confusion between 7.5 and 0.075 |
Notice the money rules. The amount is a decimal string so no system parses it as a binary floating-point number, where 0.1 + 0.2 is not 0.3. The currency is always present, because the number of decimal places depends on it: two for EUR, zero for JPY, three for KWD.
3Delivering Them as a Shared Library
A standard on paper is followed inconsistently; a standard in a library is followed by default. A small, dependency-light library, say acme-values, contains the types and every adapter a service needs: Spring Converter and Formatter implementations so the types bind from request parameters and configuration, Jackson serializers and deserializers for JSON, JPA AttributeConverters for persistence, and helpers for message schemas.
The Spring module of the library registers the converters automatically through Boot auto-configuration, including @ConfigurationPropertiesBinding ones, so adding the dependency is the whole setup. The type itself refuses invalid values, which turns a silent data error into a loud failure at the boundary.
4Using the Same Forms Everywhere
The canonical forms must be the same in every channel: REST APIs and their OpenAPI documents, Kafka and other message schemas, CSV and file exports, and configuration files. A property such as acme.limits.max-refund=500.00 EUR binds to Money through the same converter that reads API requests, so there is no second set of rules to drift.
The OpenAPI and schema definitions should reference shared component definitions for these types, so a Money field looks the same in every published contract, and contract tests in CI check that services actually produce the canonical form.
- Value typesMoney,
BusinessDate,OrderIdwith one canonical form - acme-values adaptersSpring converters, Jackson, JPA, schema helpers
- APIsJSON and OpenAPI components
- Messagesevent schemas with the same fields
- Configuration and filesproperties, CSV exports
5 layers, from the top down. Step through them one at a time.
5Versioning and Reviewing the Library
Because dozens of services depend on the library, a careless change can break many systems at once. It follows semantic versioning strictly: new types and lenient parsing are minor releases, and any change to a canonical form is a major release that needs a migration plan, because data written in the old form already exists in databases and topics. In practice, canonical forms almost never change; we add new types instead. The library has a small set of owners, changes need review from more than one domain, and its tests include round-trip checks that every value prints and parses back to itself.
The types are reviewed when a new domain arrives. A crypto product may need eight decimals, a logistics domain may need weights and units, a new market may need a new currency rule. Reviewing at that moment keeps the library a reflection of the business instead of a fossil of the first domain that built it.
6Follow-up questions
Why not just use JSR 354, the Java Money API?
It is a reasonable foundation, and Moneta provides types such as Money and FastMoney. But the problem we are solving is less about arithmetic than about one agreed text form across all systems, and the adapters for Spring, Jackson and persistence. Whether the shared type wraps BigDecimal or a JSR 354 type matters less than having one definition everyone uses.
How do you migrate services that use different forms today?
Readers first, writers second. Each service starts accepting the canonical form alongside its old one, which is a safe change. Once all readers accept it, writers switch to the canonical form one by one. Finally the old forms are removed from readers after a dated deprecation period.
Should identifiers really be a type rather than a String?
Yes for the important ones. An OrderId type cannot be passed where a CustomerId is expected, its format is validated once, and its text form is fixed. The cost is a small record per identifier, which is cheap compared with one production incident caused by swapped ids.
7Conclusion
In this answer, we traced data errors between systems to differing conversion rules for money, dates and identifiers, and fixed the cause by defining shared value types with one canonical text form each. A shared library delivers them with Spring converters and formatters, Jackson and persistence adapters, the same forms are used in APIs, messages and configuration, the library is versioned carefully because so many services depend on it, and the types are reviewed when new domains are added.
Open with
The root cause is that each service converts money, dates and identifiers by its own rules, and the values travel as primitives, so the meaning is only in people's heads.
Then, if they want more
I would fix that with shared value types, each with exactly one canonical text form. For money, a decimal amount as a string plus an ISO 4217 currency code, never a floating-point number, and the type checks that the decimals fit the currency.
Business dates as ISO 8601 dates, points in time as UTC instants, time zones as IANA ids, and each important identifier as its own type with a fixed format.
Then I would deliver them in a small shared library together with everything a service needs to use them: Spring converters and formatters, including @ConfigurationPropertiesBinding ones, Jackson serializers, JPA attribute converters and schema components, auto-configured so adding the dependency is the whole setup.
The same forms are then used everywhere, in REST APIs and OpenAPI, in message schemas and in configuration, with contract tests checking it. Because many services depend on the library, it is versioned strictly: additions are minor releases, a canonical form basically never changes, and it has clear owners and round-trip tests. Migration goes readers first, writers second.
And whenever a new domain arrives, like crypto with eight decimals, we review the types so they keep matching the business.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Framework reference, Core technologies
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Type conversion and formatting rules for money, dates and identifiers differ across your...": https://scrivio-interview-library.netlify.app/spring-boot/spring-utilities/e43e0792c2/