Bankster library, shared serialization helpers.
Bankster library, shared serialization helpers.
(extract-keys-spec keys-vec)Extracts nested opts from :keys vector.
Returns map of {field-keyword -> nested-opts-or-nil}. Returns empty map {} for empty vector (filters everything out). Returns nil for nil input (no filtering).
E.g. [:amount {:currency {:keys [:id :numeric]}}] => {:amount nil, :currency {:keys [:id :numeric]}}
Extracts nested opts from :keys vector.
Returns map of {field-keyword -> nested-opts-or-nil}.
Returns empty map {} for empty vector (filters everything out).
Returns nil for nil input (no filtering).
E.g. [:amount {:currency {:keys [:id :numeric]}}]
=> {:amount nil, :currency {:keys [:id :numeric]}}(filter-map-by-keys m keys-spec serializer-fn)Filters map m to only include keys from keys-spec.
For keys with nested opts, applies those opts recursively via serializer-fn.
Filters map `m` to only include keys from `keys-spec`. For keys with nested opts, applies those opts recursively via `serializer-fn`.
(make-money currency amount registry)(make-money currency amount registry rounding-mode)(make-money currency amount registry rounding-mode rescale)Creates Money from currency and amount for deserialization.
When rescale is provided (non-nil integer), the Currency object is cloned with
that scale instead of using its nominal scale. This allows deserializing data with
a different precision than the registry currency defines.
The rounding-mode can be a RoundingMode, keyword, or string - it will be parsed
using scale/post-parse-rounding. If not provided, falls back to
scale/*rounding-mode* or throws on precision loss.
Arguments:
currency - Currency object or identifier (keyword, string)amount - BigDecimal amountregistry - Registry to use for currency lookuprounding-mode - optional rounding mode (RoundingMode, keyword, or string)rescale - optional target scale (overrides currency's nominal scale)Creates Money from currency and amount for deserialization. When `rescale` is provided (non-nil integer), the Currency object is cloned with that scale instead of using its nominal scale. This allows deserializing data with a different precision than the registry currency defines. The rounding-mode can be a RoundingMode, keyword, or string - it will be parsed using `scale/post-parse-rounding`. If not provided, falls back to `scale/*rounding-mode*` or throws on precision loss. Arguments: - `currency` - Currency object or identifier (keyword, string) - `amount` - BigDecimal amount - `registry` - Registry to use for currency lookup - `rounding-mode` - optional rounding mode (RoundingMode, keyword, or string) - `rescale` - optional target scale (overrides currency's nominal scale)
(parse-bigdec x op-kw)Parses a value to BigDecimal.
Accepts:
bigdec (trims whitespace, removes underscores)Throws ExceptionInfo on invalid input. The op-kw argument is used in error
messages to identify the calling operation.
Parses a value to BigDecimal. Accepts: - nil -> nil - BigDecimal -> as-is - integer -> BigDecimal/valueOf - number -> BigDecimal/valueOf (note: doubles lose precision) - string -> parsed via `bigdec` (trims whitespace, removes underscores) Throws ExceptionInfo on invalid input. The `op-kw` argument is used in error messages to identify the calling operation.
(rescale-amount amount rescale rounding-mode)Rescales a BigDecimal amount to the given scale for serialization.
When rescale is nil, returns the amount as-is.
When rescale is provided, rescales using the given rounding-mode or
falls back to scale/*rounding-mode* or UNNECESSARY.
The rounding-mode can be a RoundingMode, keyword, or string.
Rescales a BigDecimal amount to the given scale for serialization. When `rescale` is nil, returns the amount as-is. When `rescale` is provided, rescales using the given rounding-mode or falls back to `scale/*rounding-mode*` or UNNECESSARY. The rounding-mode can be a RoundingMode, keyword, or string.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |