Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use clojure.core/bean recursively?

Tags:

clojure

So I think clojure.core/bean is pretty close to what I want, but I'm working with a Java application that has nested beans, such that I end up with maps like this:

{:month-total 3835.0 :name "Jan's Meat Diner" :owners #<BarOwner[] [Lcom.fancypants.BarOwner;@1fb332d}

How, do I call bean recursively on a Java object so that I can get my imaginary BarOwner object to emit itself as a map, too:

{:month-total 3835.0 :name "Jan's Meat Diner" :owners { [:name "Jack"] [:name "Jill"] } }

Edit 1

I have found that clojure/java.data and from-java is probably a better fit for this kind of thing than bean.

like image 937
Nick Klauer Avatar asked Sep 28 '12 20:09

Nick Klauer


1 Answers

Although it's probably not an ideal answer to "how to use bean recursively", using more of the richer contrib libraries under the Clojure community's site did solve it. Specifically

clojure/java.data

provides simple recursive bean resolving, and can be configured to handle java types specifically in the hairy cases. I'd recommend this to other people who want to use bean.

like image 172
Nick Klauer Avatar answered Sep 28 '22 18:09

Nick Klauer