cheshire

How to print EDN output in JSON format using Cheshire custom encoder

女生的网名这么多〃 提交于 2021-01-29 10:22:45
问题 I am newbie with Clojure and I am trying to print EDN output to valid JSON format using Cheshire custom encoder for classes defined in java. My EDN file: {:xyz #XyzBuilder "testString"} Clojure code: (defn getXyz [str] (.getXyz (XyzBuilder.) str) ) (defn custom-readers [] {'xyz/builder getXyz} ) (add-encoder com.java.sample.Xyz (fn [c jsonGenerator] (.writeString jsonGenerator (str c)))) (edn/read-string {:readers (custom-readers)} (slurp filename) ) This generates below output: {"xyz":"Xyz