Liking cljdoc? Tell your friends :D

io.randomseed.bankster.serializers.json

Bankster library, JSON-oriented serialization helpers.

Bankster library, JSON-oriented serialization helpers.
raw docstring

currency->json-full-mapclj

(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)
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)
sourceraw docstring

currency->json-mapclj

(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
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
sourceraw docstring

currency->json-stringclj

(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"
Converts Currency to a JSON string identifier.

Options:
- `:code-only?` - when truthy, namespace is omitted: `:crypto/ETH` → `"ETH"`
sourceraw docstring

json-map->currencyclj

(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)
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`)
sourceraw docstring

json-map->moneyclj

(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*.
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*`.
sourceraw docstring

json-string->currencyclj

(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)
Builds Currency from a JSON string identifier.

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

json-string->moneyclj

(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.

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.
sourceraw docstring

json-text->currencyclj

(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)
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`)
sourceraw docstring

json-text->moneyclj

(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
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
sourceraw docstring

JsonDeserializablecljprotocol

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.
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.

from-json-mapclj

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

Deserializes a value from a JSON-friendly map.

Deserializes a value from a JSON-friendly map.

from-json-stringclj

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

Deserializes a value from a JSON string.

Deserializes a value from a JSON string.
sourceraw docstring

JsonSerializablecljprotocol

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)
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)

to-json-full-mapclj

(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]}}]}
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-mapclj

(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"}

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

to-json-stringclj

(to-json-string this)
(to-json-string this opts)

Serializes the value to a canonical JSON string.

Serializes the value to a canonical JSON string.
sourceraw docstring

money->json-full-mapclj

(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)
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)
sourceraw docstring

money->json-mapclj

(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)
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)
sourceraw docstring

money->json-stringclj

(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)
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)
sourceraw docstring

money-codecclj

(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 - :map or :string

Options:

  • :representation - :map (default) or :string
  • :code-only? - passed to encoder
  • :registry - passed to decoder
  • :rounding-mode - passed to decoder
Returns a representation-aware codec map:

- `:encode`          - (Money -> json-value) where json-value is map or string
- `:decode`          - (json-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
sourceraw docstring

register-cheshire-codecs!clj

(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)
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)
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close