Enum Class CurrencyFormat
- All Implemented Interfaces:
Serializable,Comparable<CurrencyFormat>,Constable
Currency values.
Used by MarshallingContext.Builder.currencyFormat(CurrencyFormat),
Marshalled.currencyFormat(),
MarshalledProp.currencyFormat(), and
MarshalledConfig.currencyFormat() to control how Currency
values are written to text-based wire formats.
The default is ISO_CODE which preserves the historical wire output (Currency.toString() /
Currency.getCurrencyCode()).
Locale composability
SYMBOL and DISPLAY_NAME are locale-sensitive — they consult the supplied Locale
(typically the MarshallingContext.getLocale() resolved through the MarshallingSession).
ISO_CODE ignores the locale.
Round-trip caveat
Round-trip is strictly guaranteed only for ISO_CODE. SYMBOL parsing of a token
like "$" could resolve to any of USD / CAD / AUD / MXN / HKD / SGD / NZD depending on the
locale, and DISPLAY_NAME parsing is even less reliable ("Dollar" matches at least eight
ISO codes). For machine-to-machine wires, prefer ISO_CODE.
Precedence (highest to lowest)
@MarshalledProp(currencyFormat=…)on the bean property.@Marshalled(currencyFormat=…)on the bean class.@MarshalledConfig(currencyFormat=…)on-annotated classes / methods.@Rest - Programmatic
MarshallingContext.Builder.currencyFormat(CurrencyFormat). - Environment variable
MarshallingContext.currencyFormat . - The default constant (
ISO_CODE).
Parser leniency
Parsers SHALL try Currency.getInstance(String) first regardless of the parser-side
CurrencyFormat setting — this handles the ISO_CODE shape unambiguously. For
SYMBOL / DISPLAY_NAME, the parser falls back to a best-effort iterate-and-match scan
against Currency.getAvailableCurrencies().
Binary serializers
Binary serializers (BSON / CBOR / MsgPack / Prototext / Parquet) emit a UTF-8 string regardless of this
setting — there is no native Currency wire type in any supported binary format. The choice of
ISO_CODE vs SYMBOL vs DISPLAY_NAME is purely about the textual content of that
string.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionLocalized display name perCurrency.getDisplayName(Locale).ISO 4217 currency code (the default).Sentinel meaning "no value configured" — falls through to the next-higher precedence level.Currency symbol perCurrency.getSymbol(Locale). -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringformat(Currency value, CurrencyFormat format, Locale locale) Formats the specifiedCurrencyusing this format.booleanReturnstrue if this format emits a numeric wire value.static Currencyparse(String value, CurrencyFormat format, Locale locale) Parses the specified wire value into aCurrency.static CurrencyFormatReturns the enum constant of this class with the specified name.static CurrencyFormat[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
NOT_SET
Sentinel meaning "no value configured" — falls through to the next-higher precedence level. -
ISO_CODE
ISO 4217 currency code (the default).Example:
USD EUR JPY
Locale-independent. Round-trips through
Currency.getInstance(String). -
SYMBOL
Currency symbol perCurrency.getSymbol(Locale).Example (locale
en_US):$ € ¥
Locale-sensitive. The symbol is resolved against the supplied locale. Round-trip is best-effort —
"$"is shared by USD / CAD / AUD / MXN / HKD / SGD / NZD; the parser prefers the locale's default currency on ambiguity and throws when no match is found. -
DISPLAY_NAME
Localized display name perCurrency.getDisplayName(Locale).Example (locale
en_US):US Dollar Euro Japanese Yen
Locale-sensitive and even less round-trip-safe than
SYMBOL. Use only for user-facing display contexts.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
format
Formats the specifiedCurrencyusing this format.NOT_SETfalls through toISO_CODE.nulllocale is treated asLocale.ROOT.- Parameters:
value- The value to format. Can benull (returnsnull ).format- The configured format. Can benull (treated asISO_CODE).locale- The locale used bySYMBOL/DISPLAY_NAME. Can benull (treated asLocale.ROOT).- Returns:
- The formatted wire representation, or
null ifvalueisnull .
-
parse
Parses the specified wire value into aCurrency.Lenient parsing — always tries
Currency.getInstance(String)first (handlesISO_CODEunambiguously). ForSYMBOL/DISPLAY_NAMEthe parser falls back to a best-effort iterate-and-match scan againstCurrency.getAvailableCurrencies(); when multiple currencies match a symbol, prefers the locale's default currency.- Parameters:
value- The wire value. Can benull or blank (returnsnull ).format- The configured format hint. Can benull (treated asISO_CODE).locale- The locale used to disambiguateSYMBOL/DISPLAY_NAMEmatches. Can benull (treated asLocale.ROOT).- Returns:
- The parsed
Currency, ornull ifvalueisnull or blank. - Throws:
IllegalArgumentException- If the value cannot be resolved to a unique currency.
-
isNumeric
Returnstrue if this format emits a numeric wire value.Always
false — every constant emits a textual representation.- Returns:
false .
-