edn

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

Call functions read from EDN files

你说的曾经没有我的故事 提交于 2021-01-28 07:02:22
问题 I have an EDN configuration file in which the entries refer to existing functions, e.g.: :attribute-modules {:content {:class lohan.extractors.content/process} :schema {:class lohan.extractors.schema/process} :label {:class lohan.extractors.label/process} :user {:class lohan.extractors.user/process} :env {:class lohan.extractors.env/process}} Using clojure.edn/read-edn these entries are read as Symbols, but I want to be able to call them at runtime. The purpose of this is to provide a way for

Clojure RuntimeException - No reader function for tag db/id

ぐ巨炮叔叔 提交于 2019-12-10 07:31:35
问题 What is happening when I get this error in Clojure? java.lang.RuntimeException: No reader function for tag db/id 回答1: Tagged Literals This error message is related to a feature introduced in Clojure 1.7, tagged literals. Tagged literals are a simple means for extending what data types can be represented as literals in Clojure code or EDN data. Clojure ships with readers for two tagged literals, #inst and #uuid allowing literal representations of java.util.Date and java.util.UUID . Support for

Clojure & ClojureScript: clojure.core/read-string, clojure.edn/read-string and cljs.reader/read-string

拥有回忆 提交于 2019-12-08 23:04:59
问题 I am not clear about the relationship between all these read-string functions. Well, it is clear that clojure.core/read-string can read any serialized string that is output by pr[n] or even print-dup . It is also clear that clojure.edn/read-string does read strings that are formatted according to the EDN specification. However, I am starting with Clojure Script, and it is not clear if cljs.reader/read-string comply with. This question has been triggered by the fact that I had a web service

How to use clojure.edn/read to get a sequence of objects in a file?

馋奶兔 提交于 2019-12-04 18:42:09
问题 Clojure 1.5 introduced clojure.edn , which includes a read function that requires a PushbackReader . If I want to read the first five objects, I can do: (with-open [infile (java.io.PushbackReader. (clojure.java.io/reader "foo.txt"))] (binding [*in* infile] (let [edn-seq (repeatedly clojure.edn/read)] (dorun (take 5 (map println edn-seq)))))) How can I instead print out all of the objects? Considering that some of them may be nils, it seems like I need to check for the EOF, or something

How to use clojure.edn/read to get a sequence of objects in a file?

那年仲夏 提交于 2019-12-03 12:18:37
Clojure 1.5 introduced clojure.edn , which includes a read function that requires a PushbackReader . If I want to read the first five objects, I can do: (with-open [infile (java.io.PushbackReader. (clojure.java.io/reader "foo.txt"))] (binding [*in* infile] (let [edn-seq (repeatedly clojure.edn/read)] (dorun (take 5 (map println edn-seq)))))) How can I instead print out all of the objects? Considering that some of them may be nils, it seems like I need to check for the EOF, or something similar. I want to have a sequence of objects similar to what I would get from line-seq . Use :eof key http:/

How can I serialize functions at runtime in Clojure?

倖福魔咒の 提交于 2019-12-02 03:56:25
问题 Is there a way to serialize functions at runtime in Clojure? I'd like to be able to send stateless (but not pure) functions over the wire in a serialized format (probably edn, but I'm open to anything). For example... If I run prn-str on a function, I don't get what I expected/wanted. user=> (def fn1 (fn [x] (* x 2))) #'user/fn1 user=> (def data {:test 1 :key "value"}) #'user/data user=> (defn fn2 [x] (* x 2)) #'user/fn2 user=> (prn-str fn1) "#object[user$fn1 0x28b9c6e2 \"user$fn1@28b9c6e2\"]

Clojure & ClojureScript: clojure.core/read-string, clojure.edn/read-string and cljs.reader/read-string

微笑、不失礼 提交于 2019-11-30 02:59:11
I am not clear about the relationship between all these read-string functions. Well, it is clear that clojure.core/read-string can read any serialized string that is output by pr[n] or even print-dup . It is also clear that clojure.edn/read-string does read strings that are formatted according to the EDN specification . However, I am starting with Clojure Script, and it is not clear if cljs.reader/read-string comply with. This question has been triggered by the fact that I had a web service that was emiting clojure code serialized that way: (with-out-str (binding [*print-dup* true] (prn tags))