io.randomseed.bankster.serializers.json
added in 2.1.0
Bankster library, JSON-oriented serialization helpers.
currency->json-full-map
added in 2.1.0
(currency->json-full-map c)(currency->json-full-map c opts)Converts Currency to a full JSON-friendly map with all fields.
Canonical shape: - :id - currency identifier string (e.g. “PLN” or “crypto/ETH”) - :numeric - ISO numeric code (or -1 if absent) - :scale - decimal places (or -1 for auto-scaled) - :kind - kind string (e.g. “FIAT”, “DECENTRALIZED”) - :domain - domain string (e.g. “ISO-4217”, “CRYPTO”)
Options: - :code-only? - when truthy, namespace is omitted in :id - :keys - vector of keys to include (filters output)
currency->json-map
added in 2.1.0
(currency->json-map c)(currency->json-map c opts)Converts Currency to a minimal JSON-friendly map.
Minimal shape (by default): - :id - currency identifier string
When :full? is truthy, delegates to currency->json-full-map.
Options: - :code-only? - when truthy, namespace is omitted in :id - :full? - when truthy, returns full map via currency->json-full-map - :keys - (only with :full?) vector of keys to include
currency->json-string
added in 2.1.0
(currency->json-string c)(currency->json-string c opts)Converts Currency to a JSON string identifier.
Options: - :code-only? - when truthy, namespace is omitted: :crypto/ETH → "ETH"
json-map->currency
added in 2.1.0
(json-map->currency m)(json-map->currency m opts)Builds Currency from a JSON-friendly map.
Accepts both keyword and string keys. Uses :id for lookup.
Options: - :registry - registry to use for lookup (default: registry/get)
json-map->money
added in 2.1.0
(json-map->money m)(json-map->money m opts)Builds Money from a JSON-friendly map.
Accepts both keyword and string keys.
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. Downscaling requires :rounding-mode or scale/*rounding-mode*.
json-string->currency
added in 2.1.0
(json-string->currency s)(json-string->currency s opts)Builds Currency from a JSON string identifier.
Options: - :registry - registry to use for lookup (default: registry/get)
json-string->money
added in 2.1.0
(json-string->money s)(json-string->money s opts)Builds Money from a JSON string.
Accepts: - amount-first: “12.30 PLN” - currency-first: “PLN 12.30” - no-whitespace: “PLN12.30” (best-effort)
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.
For scale-sensitive workflows prefer map representation.
json-text->currency
added in 2.1.0
(json-text->currency s)(json-text->currency s opts)Parses JSON text and deserializes Currency.
Expects JSON object (map) or JSON string representation.
Options: - :representation - :auto (default), :map, or :string - :parse-fn - custom parser fn (String -> Clojure value) - :key-fn - Cheshire key-fn - :bigdecimals? - when using Cheshire, bind cheshire.parse/*use-bigdecimals?* (default true) - :registry - registry to use for currency lookup (default: registry/get)
json-text->money
added in 2.1.0
(json-text->money s)(json-text->money s opts)Parses JSON text and deserializes Money.
Expects JSON object (map) or JSON string representation.
Parser selection: - If :parse-fn is provided, it is used to parse the string into a Clojure value. - Otherwise, Cheshire is used when available.
Options: - :representation - :auto (default), :map, or :string - :parse-fn - custom parser fn (String -> Clojure value) - :key-fn - Cheshire key-fn (e.g. keyword, identity, nil) - :bigdecimals? - when using Cheshire, bind cheshire.parse/*use-bigdecimals?* (default true) - :registry - registry to use for currency lookup (default: registry/get) - :rounding-mode - rounding mode for rescaling - :rescale - integer scale override
JsonDeserializable
protocol
added in 2.1.0
Protocol for JSON 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-json-map
added in 2.1.0
(from-json-map type-token m)(from-json-map type-token m opts)Deserializes a value from a JSON-friendly map.
from-json-string
added in 2.1.0
(from-json-string type-token s)(from-json-string type-token s opts)Deserializes a value from a JSON string.
JsonSerializable
protocol
added in 2.1.0
Protocol for JSON serialization of Bankster types.
Options map supports: - :code-only? - when truthy, namespace is omitted: :crypto/ETH → "ETH" - :full? - when truthy, delegates to to-json-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-json-full-map
added in 2.1.0
(to-json-full-map this)(to-json-full-map this opts)Serializes the value to a full JSON-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-json-map
added in 2.1.0
(to-json-map this)(to-json-map this opts)Serializes the value to a minimal JSON-friendly map. For Money: {:currency “PLN”, :amount “12.30”} For Currency: {:id “PLN”}
to-json-string
added in 2.1.0
(to-json-string this)(to-json-string this opts)Serializes the value to a canonical JSON string.
money->json-full-map
added in 2.1.0
(money->json-full-map money)(money->json-full-map money opts)Converts Money to a full JSON-friendly map with all fields.
Full shape: - :currency - full currency map (via currency->json-full-map) - :amount - amount as string - 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->json-map
added in 2.1.0
(money->json-map money)(money->json-map money opts)Converts Money to a minimal JSON-friendly map.
Minimal shape: - :currency - currency identifier string (e.g. “PLN” or “crypto/USDT”) - :amount - amount as a string (plain BigDecimal, scale preserved)
When :full? is truthy, delegates to money->json-full-map.
Options: - :code-only? - when truthy, namespace is omitted: :crypto/ETH → "ETH" - :full? - when truthy, returns full map via money->json-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->json-string
added in 2.1.0
(money->json-string money)(money->json-string money opts)Converts Money to a canonical JSON string.
Canonical form: <amount> <currency-id-str> (e.g. “12.30 PLN”). Locale-independent.
Options: - :code-only? - when truthy, namespace is omitted: :crypto/ETH → "ETH" - :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:
:encode- (Money -> json-value) where json-value is map or string:decode- (json-value -> Money):representation-:mapor:string
Options: - :representation - :map (default) or :string - :code-only? - passed to encoder - :registry - passed to decoder - :rounding-mode - passed to decoder
register-cheshire-codecs!
added in 2.1.0
(register-cheshire-codecs!)(register-cheshire-codecs! {:keys [representation code-only? add-encoder], :as opts})Registers Cheshire encoders for io.randomseed.bankster.Money.
Notes: - This function does not add any dependencies. If Cheshire is not on the classpath it throws. - Cheshire registration affects encoding; decoding remains explicit via json-map->money / json-string->money. - :representation selects whether Money is encoded as an object (:map) or a JSON string (:string).
Options: - :representation - :map (default) or :string - :code-only? - when truthy, namespace is omitted in currency identifiers - :add-encoder - custom add-encoder fn (for testing)