Skip to content

Instantly share code, notes, and snippets.

@palesz
Created October 6, 2016 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save palesz/7a5ef53aba15680e768d83cd762ee7ec to your computer and use it in GitHub Desktop.
Save palesz/7a5ef53aba15680e768d83cd762ee7ec to your computer and use it in GitHub Desktop.
Convert any arbitrary Java object hierarchy to Clojure map of maps
(ns cljify)
(require 'clojure.string)
(require 'clojure.walk)
(defn cljify1 [o]
(when (not (nil? o))
(let [cname (.getName (class o))
s (partial clojure.string/starts-with? cname)]
(cond
(s "java.lang.Class") o
(s "java.util") (into [] o)
(s "java.lang") o
(s "clojure") o
:else (->> (bean o) (map identity) (into {}))))))
(defn cljify [o]
(clojure.walk/prewalk cljify1 o))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment