Hi, I have a jar files with more than 200 DTO classes. Some have only primitive data type values and some have other beans from the same jar. I am trying to traverse through a class hierarchy to find the field count. If a class has a mix of some primitive types and other java classes, then the total field count is to be computed by looking up the field count from those fields.
I am having a map of lists. I believe some kind of flat map operation should be useful here. But I see a need for recursive travel through hierarchy. So not sure how to proceed. So I am first trying to solve it imperatively. However, reflect/reflect does not return Class objects, It is returning Symbols. So my below filter function is failing. Pls can you help how to covert symbols into Class objects (def primitive-types #{ java.lang.Boolean java.lang.Character java.lang.Byte java.lang.Short java.lang.Integer java.lang.Long java.lang.Float java.lang.Double java.lang.String }) ; using hash-maps as I yet don't know how to mutate maps in clojure (def refcounts-map (java.util.HashMap.)) (def final-ref-counts-map (java.util.HashMap.)) (defn all-fields-are-of-primitive-type? [fields-list] (every? #(primitive-types %) fields-list) ) (defn init-ref-counts-from-class-hierarchy [types-list] ; A list of class objects (when-not (empty? types-list) (let [cur-type (first types-list) cur-type-data-fields (->> cur-type (reflect/reflect ) (:members) (filter #(instance? clojure.reflect.Field %)) (map #(:type %)) ;<----------------This is not a sequence of Class objects. It is giving Symbols! ) ] (if (all-fields-are-of-primitive-type? cur-type-data-fields) ;<------- This is always failing!! (.put final-ref-counts-map cur-type (count cur-type-data-fields)) (.put refcounts-map cur-type [cur-type-data-fields 0]) ) (recur (rest types-list)) ) ) ) (defn get-reference-counts [types-list] (do (init-ref-counts-from-class-hierarchy types-list) ;TODO: initiate recursive travel through )) (get-reference-counts (take 2 (vals dto-class-objects))) (pp/pprint refcounts-map) (pp/pprint final-ref-counts-map) -- 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/d/optout.