Skip to content

Commit

Permalink
closes #126
Browse files Browse the repository at this point in the history
  • Loading branch information
justinhrobbins committed Feb 24, 2014
1 parent 9fa5117 commit 1dc0e33
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -37,6 +38,21 @@ public static void filterFields(Object obj, Set<String> fields)
for (PropertyDescriptor propertyDesc : beanInfo.getPropertyDescriptors()) {
String propertyName = propertyDesc.getName();

// if (propertyDesc.getPropertyType().equals(Collection.class)) {
// Method getter = propertyDesc.getReadMethod();
// filterFields(getter.invoke(obj), fields);
// }

// is the current property a collection?
Method getter = propertyDesc.getReadMethod();
Object values = getter.invoke(obj);
if (values instanceof Collection<?>) {
// run the filter over the fields in the collection
for (Object value : (Collection<?>) values) {
filterFields(value, fields);
}
}

// if we don't explicitly want this field
if (fieldsMap.get(propertyName) == null) {
Method setter = propertyDesc.getWriteMethod();
Expand Down

0 comments on commit 1dc0e33

Please sign in to comment.