Closed ikitommi closed 7 years ago
next time then. Dunno about the virgil, I'll submit an issue there.
So, this could be used to convert to/from camelCase by passing opts like so:
{:encode-key-fn (comp name to-camel-case)
:decode-key-fn (comp to-kebab-case keyword)}
Assuming the to-camel-case and to-kebab-case have a signature something like this:
; Takes a keyword :foo-bar and converts it to a string "fooBar"
(defn- camel-case [k]
(clojure.string/replace k #"[-_](.)" #(-> % (nth 1) clojure.string/upper-case))))
If so, then this pull request means I can switch from Cheshire to jsonista. Nice work!
Yes:
(require '[jsonista.core :as j])
(defn reverse-string [s] (apply str (reverse s)))
(def mapper
(j/object-mapper {:encode-key-fn (comp reverse-string name)
:decode-key-fn (comp keyword reverse-string)}))
(-> {:kikka "kukka"}
(doto prn)
(j/write-value-as-string mapper)
(doto prn)
(j/read-value mapper)
prn)
; {:kikka "kukka"}
; "{\"akkik\":\"kukka\"}"
; {:kikka "kukka"}
remove
:keywordize?
in favour of:here's the relevant tests:
With defaults, use the same code as before, so no change in perf. Except one can transform keys in single sweep making things much faster.