lancepantz / clj-yaml

YAML encoding and decoding for Clojure via SnakeYAML
Other
91 stars 52 forks source link

serialized !!clojure.lang.Symbol has no content #12

Open trevor opened 11 years ago

trevor commented 11 years ago
(clj-yaml.core/generate-string {:x :y :a "b"} :dumper-options {:flow-style :flow})
;= "{x: y, a: b}\n"

(clj-yaml.core/generate-string {:x :y :a "b"} :dumper-options {:flow-style :block})
;= "x: y\na: b\n"

(clj-yaml.core/generate-string {:x :y :a 'b} :dumper-options {:flow-style :flow})
;= "{x: y, a: !!clojure.lang.Symbol {}}\n"

(clj-yaml.core/generate-string {:x :y :a 'b} :dumper-options {:flow-style :block})
;= "x: y\na: !!clojure.lang.Symbol {}\n"
trevor commented 11 years ago

This is fixed with:

  (doto (DumperOptions.)
    (.setAllowReadOnlyProperties true)

example (with modified fn's):

=>  (println (yaml-dump {:x :y/z :a 'b/c/d}))
---
x: z
a: !!clojure.lang.Symbol
  name: d
  namespace: b/c
...
trevor commented 11 years ago

(note that setAllowReadOnlyProperties isn't available in snakeyaml 1.5, but is in 1.12)