Created
October 6, 2016 00:11
-
-
Save palesz/7a5ef53aba15680e768d83cd762ee7ec to your computer and use it in GitHub Desktop.
Convert any arbitrary Java object hierarchy to Clojure map of maps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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