Hey I know this is super old post but what would the reverse look like, eg. 
recursively convert Clojure to java map

On Saturday, October 15, 2011 at 4:10:32 AM UTC-5, Baishampayan Ghose wrote:
>
> > I have a Java Map contains Map of Maps/List (JSON like map) and have
> > to convert to Clojure map (This happens at Java - Clojure Interop), So
> > I have written a converter function 'as-clj-map' by modifying the
> > clojure walk functions, It works fine, but consume lot of cpu when the
> > data structure is quit big. Any suggestions to improve this code?
>
> What about using protocols for this job?
>
> (defprotocol ConvertibleToClojure
>   (->clj [o]))
>
> (extend-protocol ConvertibleToClojure
>   java.util.Map
>   (->clj [o] (let [entries (.entrySet o)]
>                (reduce (fn [m [^String k v]]
>                          (assoc m (keyword k) (->clj v)))
>                        {} entries)))
>
>   java.util.List
>   (->clj [o] (vec (map ->clj o)))
>
>   java.lang.Object
>   (->clj [o] o)
>
>   nil
>   (->clj [_] nil))
>
> (defn as-clj-map
>   [m]
>   (->clj m))
>
>
> Let me know if this works for you & meets your performance requirements.
>
> Regards,
> BG
>
> -- 
> Baishampayan Ghose
> b.ghose at gmail.com
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/30c8edaf-bafe-4e78-9503-430d9f2c85ef%40googlegroups.com.

Reply via email to