lancepantz / clj-yaml

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

Problem with maps using integer keys #15

Open cassiel opened 11 years ago

cassiel commented 11 years ago
(yaml/generate-string {46 "MAYBE" 52 "DEFINITELY"})
"{46: MAYBE, 52: DEFINITELY}\n"

(yaml/parse-string (yaml/generate-string {46 "MAYBE" 52 "DEFINITELY"}))
{nil "DEFINITELY"}

This seems to be legal YAML, and SnakeYAML itself seems to handle it AFAICT.

radix commented 11 years ago

I ran into this when trying to parse RAML: http://raml.org/

It uses numeric keys representing HTTP response codes.

radix commented 11 years ago

I discovered a workaround -- apparently the bug is in the behavior of "keywordizing" the keys in a YAML map.

If you use (parse-string yaml false), this indicates that keywordization shouldn't happen, and keys will be normal strings (actually this is what I wanted anyway, since I was converting the keywords to strings manually before).