Was there a reason why a method wasn't included in the ReflectionUtils class to get all of the declared fields for a particular class and all super classes? There is a method to get all of the declared methods but not fields.
The reason I ask is that I've been playing around with the new BeanPropertyRowMapper that's included in 2.1 M1 and it only pulls the fields that are declared by the the mapped class. A problem I see with that is what if I have a class that extends a base class that holds additional fields that need to be mapped to. By just pulling the declared fields for the mapped class alone and not it's super classes, all of the fields that I'm querying won't be populated.
All it would take is to include the following method in the ReflectionUtils. The helper methods already exist to get the job done.
And also to fix the BeanPropertyRowMapper it would just take fixing one line. The line in the initialize method:Code:/** * Get all declared fields on the leaf class and all superclasses. Leaf * class fields are included first. */ public static Field[] getAllDeclaredFields(Class leafClass) throws llegalArgumentException { final List l = new LinkedList(); doWithFields(leafClass, new FieldCallback() { public void doWith(Field f) { l.add(f); } }); return (Field[]) l.toArray(new Field[l.size()]); }
Would now be:Code:Field[] f = mappedClass.getDeclaredFields();
Any thoughts?Code:Field[] f = ReflectionUtils.getAllDeclaredFields(mappedClass);
-Ben


Reply With Quote