com.isomorphic.js
Class JSONFilter

java.lang.Object
  |
  +--com.isomorphic.js.JSONFilter

public class JSONFilter
extends java.lang.Object

This class provides you to specify the properties of a Map, Bean or Collection of Maps or Beans to serialize to JSON when processed bo JSTranslater.toJS(). When JSONFilter wraps a Bean or Map, the filter is applied directly to the Bean/Map. When JSONFilter wraps a Collection (or Iterator), the filter applies to the immediate members of the Collection or Iterator and only when those elements are Beans or Maps themselves. So, for example:

 String[] propsToKeep = {"foo", "bar"};
 MyBean myBean = new MyBean();
 JSTranslater.get().toJS(new JSONFilter(myBean, propsToKeep), out);
 
The above would serialize only "foo" and "bar" properties of MyBean. If the above code passed a list of MyBean classes to the JSONFilter constructor, then the filter would be applied to each element of that list.

One of the JSONFilter constructors takes an IBeanFilter interface that allows you to pass a custom Object->Map converter. You can use this to convert complex beans that require more translation than a simple list of properties to include.

See Also:
JSTranslater.toJS(Object, Writer), IBeanFilter

Constructor Summary
JSONFilter(java.lang.Object obj, java.util.Collection propsToKeep)
          Creates a new JSONFilter.
JSONFilter(java.lang.Object obj, DataSource dataSource)
          Creates a new JSONFilter.
JSONFilter(java.lang.Object obj, IBeanFilter beanFilter)
          Creates a new JSONFilter.
JSONFilter(java.lang.Object obj, java.lang.Object[] propsToKeep)
          Creates a new JSONFilter.
JSONFilter(java.lang.Object obj, java.lang.String dataSource)
          Creates a new JSONFilter.
 
Method Summary
 IBeanFilter getBeanFilter()
           
 java.lang.Object getObj()
           
 

Constructor Detail

JSONFilter

public JSONFilter(java.lang.Object obj,
                  java.lang.String dataSource)
           throws java.lang.Exception
Creates a new JSONFilter. The set of properties to keep is defined by the set of fields defined on a DataSource.
Parameters:
obj - The object to serialize
dataSource - The name of the dataSource from which to fetch field names for use as the set of properties on the object to keep.
Throws:
java.lang.Exception - If the dataSource cannot be looked up.

JSONFilter

public JSONFilter(java.lang.Object obj,
                  DataSource dataSource)
Creates a new JSONFilter. The set of properties to keep is defined by the set of fields defined on a DataSource.
Parameters:
obj - The object to serialize
dataSource - The dataSource instance from which to fetch field names for use as the set of properties on the object to keep.

JSONFilter

public JSONFilter(java.lang.Object obj,
                  java.util.Collection propsToKeep)
Creates a new JSONFilter.
Parameters:
obj - The object to serialize
propsToKeep - properties to keep.

JSONFilter

public JSONFilter(java.lang.Object obj,
                  java.lang.Object[] propsToKeep)
Creates a new JSONFilter.
Parameters:
obj - The object to serialize
propsToKeep - properties to keep.

JSONFilter

public JSONFilter(java.lang.Object obj,
                  IBeanFilter beanFilter)
Creates a new JSONFilter. This signature allows you to specify a custom class to convert the object to a Map, using the IBeanFilter interface.
Parameters:
obj - The object to serialize
propsToKeep - properties to keep.
See Also:
IBeanFilter
Method Detail

getBeanFilter

public IBeanFilter getBeanFilter()
Returns:
the current bean filter

getObj

public java.lang.Object getObj()
Returns:
object to serialize