(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}}
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close