Search code examples
javaclojuremappinginteropjavabeans

Custom accessor strategy for Clojure `from-java`


Is there any way to customise the accessor strategy used in clojure.java.data/from-java? from-java is part of the java.data function lib.

I recently updated a third-pary Java-library that used to follow the JavaBean get and set pattern. However, after the update they went from getProperty() to property()...

I guess this change renders the from-java function not suitable in this case, no surprise since the objects are no longer proper JavaBeans.

Is there any way of making from-java aware of this accessor-pattern, or are there any other recursive mapping-mechanisms that supports this?


Solution

  • from-java is a multimethod, do you can override it for any class you like. There is no mechanism for teaching it an alternate naming convention (and if there were such a mechanism, I imagine it would have trouble with "every method with any name at all represents a property"). Therefore you'll have to write manual conversions, but at least the recursion will be handled for you.