clj-commons / clj-yaml

YAML encoding and decoding for Clojure
Other
122 stars 26 forks source link

Feature request: Add interface for Representer #133

Open conao3 opened 3 months ago

conao3 commented 3 months ago

I notice dumping clojure symbol using clj-yaml, it output !!clojure.lang.Symbol.

user> (require '[clj-yaml.core :as yaml])
user> (yaml/generate-string {:arglists '([] [x])})
"arglists:\n- []\n- - !!clojure.lang.Symbol {}\n"

I want that it just outputs as a string.

My assumption would be an API like this

(yaml/generate-string {:arglists '([] [x])} {:dumper-options :serialize-tag {clojure.lang.Symbol str}})

workaround

thanks @lread

(require '[clj-yaml.core :as yaml]
         '[clojure.walk :as walk])

(defn prep [form]
  (walk/prewalk (fn [item] (if (symbol? item)
                             (str item)
                             item))
                form))

(-> {:arglists '([] [x])} prep yaml/generate-string)
;; => "arglists:\n- []\n- [x]\n"

pointer

from @lread's comment, maybe this feature is Representer of SnakeYAML.