(encode-collection es gen)(encode-keyword x gen)(encode-str o gen)(module {:keys [handlers]})Create a Jackson Databind module to support losslessly encoded tagged values.
This provides both encoders and decoders and is a means of using jsonista to replace something
like transit, while still maintaining support for more EDN types. Types are encoded using a JSON
list and a customizable tag. For example, :foo/bar would serialize to ["!kw", "foo/bar"]
by default, where the first string in the JSON list is a tag for what follows.
(def mapper (j/object-mapper
{:decode-key-fn true
:modules [(jt/module
{:handlers {Keyword {:tag "!kw"
:encode jt/encode-keyword
:decode keyword}
PersistentHashSet {:tag "!set"
:encode jt/encode-collection
:decode set}}})]}))
(-> {:kikka #{:kukka :kakka}} (j/write-value-as-string mapper) (doto prn) (j/read-value mapper)) ; prints "{"kikka":["!set",[["!kw","kukka"],["!kw","kakka"]]]}" ; => {:kikka #{:kukka :kakka}}
Create a Jackson Databind module to support losslessly encoded tagged values.
This provides both encoders and decoders and is a means of using jsonista to replace something
like transit, while still maintaining support for more EDN types. Types are encoded using a JSON
list and a customizable tag. For example, `:foo/bar` would serialize to `["!kw", "foo/bar"]`
by default, where the first string in the JSON list is a tag for what follows.
(def mapper (j/object-mapper
{:decode-key-fn true
:modules [(jt/module
{:handlers {Keyword {:tag "!kw"
:encode jt/encode-keyword
:decode keyword}
PersistentHashSet {:tag "!set"
:encode jt/encode-collection
:decode set}}})]}))
(-> {:kikka #{:kukka :kakka}}
(j/write-value-as-string mapper)
(doto prn)
(j/read-value mapper))
; prints "{\"kikka\":[\"!set\",[[\"!kw\",\"kukka\"],[\"!kw\",\"kakka\"]]]}"
; => {:kikka #{:kukka :kakka}}(serializer tag encoder)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 |