org.apache.shindig.protocol.conversion
Class BeanFilter
java.lang.Object
org.apache.shindig.protocol.conversion.BeanFilter
public class BeanFilter
- extends Object
Filter content of a bean according to fields list.
Fields list should be in lower case. And support sub objects using dot notation.
For example to get only the "name" field of the object in the "view" field,
specify "view.name" (and also specify "view" to get the view itself).
Use "*" to get all fields, or "view.*" all sub fields of view (see tests).
Note that specifying "view" does NOT imply "view.*" and that
specifying "view.*" require specifying "view" in order to get the view itself.
(Note that the processBeanFilter resolve the last limitation)
Note this code create a new object for each filtered object.
Filtering can be done also using cglib.InterfaceMaker and reflect.Proxy.makeProxyInstance
That results with an object that have same finger print as source, but cannot be cast to it.
- Since:
- 2.0.0
|
Nested Class Summary |
static interface |
BeanFilter.Unfiltered
Annotation for required field that should not be filtered |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ALL_FIELDS
public static final String ALL_FIELDS
- See Also:
- Constant Field Values
DELIMITER
public static final String DELIMITER
- See Also:
- Constant Field Values
BeanFilter
public BeanFilter()
createFilteredBean
public Object createFilteredBean(Object data,
Set<String> fields)
- Create a proxy object that filter object fields according to set of fields.
If a field is not specified in the set, the get method will return null.
(Primitive returned type cannot be filtered)
The filter is done recursively on sub items.
- Parameters:
data - the object to filterfields - list of fields to pass through.
processBeanFields
public Set<String> processBeanFields(Collection<String> fields)
getBeanFields
public List<String> getBeanFields(Class<?> bean,
int depth)
- Provide list of all fields for a specific bean
- Parameters:
bean - the class to list fields fordepth - maximum depth of recursive (mainly for infinite loop protection)
Copyright © 2007-2012. All Rights Reserved.