io.randomseed.bankster.serializers.edn

added in 2.1.0

Bankster library, EDN-oriented serialization helpers.

currency->edn-full-map

added in 2.1.0

(currency->edn-full-map c)(currency->edn-full-map c opts)

Converts Currency to a full EDN-friendly map with all fields.

Full shape: - :id - currency identifier keyword (may be namespaced) - :numeric - ISO numeric code (or -1 if absent) - :scale - decimal places (or -1 for auto-scaled) - :domain - domain keyword (e.g. :ISO-4217, :CRYPTO) - :kind - kind keyword (e.g. :FIAT, :DECENTRALIZED)

Options: - :code-only? - when truthy, namespace is omitted in :id - :keys - vector of keys to include (filters output)

currency->edn-keyword

added in 2.1.0

(currency->edn-keyword c)(currency->edn-keyword c opts)

Converts Currency to an EDN keyword identifier.

Options: - :code-only? - when truthy, namespace is omitted: :crypto/ETH:ETH

currency->edn-map

added in 2.1.0

(currency->edn-map c)(currency->edn-map c opts)

Converts Currency to a minimal EDN-friendly map.

Minimal shape (by default): - :id - currency identifier keyword

When :full? is truthy, delegates to currency->edn-full-map.

Options: - :code-only? - when truthy, namespace is omitted in :id - :full? - when truthy, returns full map via currency->edn-full-map - :keys - (only with :full?) vector of keys to include

currency->edn-string

added in 2.1.0

(currency->edn-string c)(currency->edn-string c opts)

Converts Currency to an EDN tagged literal string.

Format: #currency <keyword> (e.g. #currency :PLN or #currency :crypto/ETH)

Options: - :code-only? - when truthy, namespace is omitted: :crypto/ETH:ETH

edn-keyword->currency

added in 2.1.0

(edn-keyword->currency k)(edn-keyword->currency k opts)

Builds Currency from an EDN keyword identifier.

Options: - :registry - registry to use for lookup (default: registry/get)

edn-map->currency

added in 2.1.0

(edn-map->currency m)(edn-map->currency m opts)

Builds Currency from an EDN map.

Uses :id for lookup.

Options: - :registry - registry to use for lookup (default: registry/get)

edn-map->money

added in 2.1.0

(edn-map->money m)(edn-map->money m opts)

Builds Money from an EDN map.

Options: - :registry - registry to use for currency lookup (default: registry/get) - :rounding-mode - rounding mode for rescaling (RoundingMode, keyword, or string) - :rescale - integer scale to use instead of currency’s nominal scale. When provided, the Currency is cloned with this scale before creating Money. This prevents data loss when the registry currency has a smaller scale than the incoming data.

edn-string->currency

added in 2.1.0

(edn-string->currency s)(edn-string->currency s opts)

Builds Currency from an EDN tagged literal string.

Options: - :registry - registry to use for lookup (default: registry/get)

edn-string->money

added in 2.1.0

(edn-string->money s)(edn-string->money s opts)

Builds Money from an EDN tagged literal string.

Accepts: - #money[12.30M PLN] - #money/crypto[1.5M ETH] - #money{:currency :PLN :amount 12.30M}

Options: - :registry - registry to use for currency lookup (default: registry/get) - :rounding-mode - rounding mode for rescaling (RoundingMode, keyword, or string) - :rescale - integer scale to use instead of currency’s nominal scale

EdnDeserializable

protocol

added in 2.1.0

Protocol for EDN deserialization of Bankster types.

Options map supports: - :registry - registry to use for currency lookup (default: registry/get) - :rounding-mode - rounding mode for rescaling (RoundingMode, keyword, or string) - :rescale - integer scale to use instead of currency’s nominal scale. When provided, the Currency object is cloned with this scale before creating Money. This prevents data loss when the registry currency has a smaller scale than the incoming data.

members

from-edn-map

added in 2.1.0

(from-edn-map type-token m)(from-edn-map type-token m opts)

Deserializes a value from an EDN map.

from-edn-string

added in 2.1.0

(from-edn-string type-token s)(from-edn-string type-token s opts)

Deserializes a value from an EDN string (tagged literal format).

EdnSerializable

protocol

added in 2.1.0

Protocol for EDN serialization of Bankster types.

Options map supports: - :code-only? - when truthy, namespace is omitted: :crypto/ETH:ETH - :full? - when truthy, delegates to to-edn-full-map for full serialization - :keys - vector of keys to include; supports nested opts via map elements - :rescale - integer scale to rescale amounts to (requires :rounding-mode for downscaling)

members

to-edn-full-map

added in 2.1.0

(to-edn-full-map this)(to-edn-full-map this opts)

Serializes the value to a full EDN-friendly map with all available fields. For Currency: {:id, :numeric, :scale, :kind, :domain} For Money: {:currency {…}, :amount} plus any extended fields.

Options: - :keys - vector of keys to include; nested opts via map elements e.g. {:keys [:amount {:currency {:keys :id :numeric}}]}

to-edn-map

added in 2.1.0

(to-edn-map this)(to-edn-map this opts)

Serializes the value to a minimal EDN-friendly map. For Money: {:currency :PLN, :amount 12.30M} For Currency: {:id :PLN}

to-edn-string

added in 2.1.0

(to-edn-string this)(to-edn-string this opts)

Serializes the value to an EDN string (tagged literal format).

money->edn-full-map

added in 2.1.0

(money->edn-full-map money)(money->edn-full-map money opts)

Converts Money to a full EDN-friendly map with all fields.

Full shape: - :currency - full currency map (via currency->edn-full-map) - :amount - BigDecimal amount - Plus any extended fields from the Money record

Options: - :code-only? - when truthy, namespace is omitted in currency :id - :keys - vector of keys to include; supports nested opts for :currency e.g. {:keys [:amount {:currency {:keys :id :numeric}}]} - :rescale - integer scale to rescale amounts to before serialization - :rounding-mode - rounding mode for rescaling (RoundingMode, keyword, or string)

money->edn-map

added in 2.1.0

(money->edn-map money)(money->edn-map money opts)

Converts Money to a minimal EDN-friendly map.

Minimal shape: - :currency - currency identifier keyword (e.g. :PLN or :crypto/USDT) - :amount - BigDecimal amount (scale preserved)

When :full? is truthy, delegates to money->edn-full-map.

Options: - :code-only? - when truthy, namespace is omitted: :crypto/ETH:ETH - :full? - when truthy, returns full map via money->edn-full-map - :keys - (only with :full?) vector of keys to include - :rescale - integer scale to rescale amounts to before serialization - :rounding-mode - rounding mode for rescaling (RoundingMode, keyword, or string)

money->edn-string

added in 2.1.0

(money->edn-string money)(money->edn-string money opts)

Converts Money to an EDN tagged literal string.

Format: - ISO currencies: #money[12.30M PLN] - Namespaced currencies: #money/crypto[1.5M ETH]

Options: - :code-only? - when truthy, always uses #money[...] format without namespace - :rescale - integer scale to rescale amounts to before serialization - :rounding-mode - rounding mode for rescaling (RoundingMode, keyword, or string)

money-codec

added in 2.1.0

(money-codec)(money-codec {:keys [representation code-only? registry rounding-mode], :as opts})

Returns a representation-aware codec map for EDN:

  • :encode - (Money -> edn-value) where edn-value is map or string
  • :decode - (edn-value -> Money)
  • :representation - :map or :string

Options: - :representation - :map (default) or :string - :code-only? - passed to encoder - :registry - passed to decoder - :rounding-mode - passed to decoder