Some Java frameworks will accept public final fields as Java bean fields. In that case, a Clojure record can be used directly (although I'm not sure if we're making an assumption about Clojure records that might change). This has actually worked for my limited needs in this space.
The only other cases I've run into this are instances where I wanted to create a first-class Java (and javadoc'd) API for consumers, so I wrote a Java interface that followed JavaBean conventions, and simply reified it in Clojure. That all said, if I had to do this often (I haven't), I probably would have written some form of defbean macro that created a record and the corresponding getters for Java land. Unfortunately I'm not aware of such a thing, but it seems like it would be straightforward to implement. On Friday, August 16, 2013 12:29:40 PM UTC-5, Sean Corfield wrote: > > I was working with a Java library recently and needed to create a > "Java bean" to pass into it. It can be done via `gen-class` but it > seems kind of verbose having to explicitly write out all of the > getters and setters, and it seems you could also do it via `deftype` > but that's also rather painful (I started looking at that in the hope > of automating it via a macro but it seemed difficult to have > overloaded constructors and I needed both a no-arg constructor and one > that took all the bean attributes). > > What do people do when they need a "Java bean" for interop when using > Clojure with a Java library? This seems like it should be common > enough that I would have expected it to be part of clojure.java.data > but it isn't... > > Just a class name and a list of property names and (perhaps optional) > types should be all the ceremony we need to write... and I don't want > to reinvent the wheel if that is already out there somewhere? > -- > Sean A Corfield -- (904) 302-SEAN > An Architect's View -- http://corfield.org/ > World Singles, LLC. -- http://worldsingles.com/ > > "Perfection is the enemy of the good." > -- Gustave Flaubert, French realist novelist (1821-1880) > -- -- 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. For more options, visit https://groups.google.com/groups/opt_out.