-
-
Save cgrand/283896 to your computer and use it in GitHub Desktop.
This file contains 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
(defn unbean [m] | |
"Tries to recreate a simple JavaBean object from map m" | |
(let [obj (.newInstance (:class m))] | |
(doseq [#^java.beans.PropertyDescriptor pd (-> String java.beans.Introspector/getBeanInfo .getPropertyDescriptors) | |
:let [wm (.getWriteMethod pd) k (-> pd .getName keyword)] :when (and wm (contains? m k))] | |
(.invoke wm obj (to-array [(m k)]))) | |
obj)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment