metosin / jsonista

Clojure library for fast JSON encoding and decoding.
https://cljdoc.org/d/metosin/jsonista
Eclipse Public License 2.0
422 stars 30 forks source link

make tagged-module more generic #39

Closed ikitommi closed 3 years ago

ikitommi commented 3 years ago
(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}}