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 by 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.

Also see the IToJSON interface, which you can implement to control JavaScript translation of your object regardless of how it is passed to the JSTranslater.

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

Constructor Summary
JSONFilter(java.lang.Object obj, java.util.Collection propsToKeep)
          Creates a new JSONFilter.
JSONFilter(java.lang.Object obj, DataSource dataSource, boolean dropExtraFields)
          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, boolean dropExtraFields)
          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,
                  boolean dropExtraFields)
Creates a new JSONFilter. The set of properties to keep is defined by the set of fields defined on a DataSource. This constructor applies a DataSourceBeanFilter to the object.
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.
See Also:
DataSourceBeanFilter

JSONFilter

public JSONFilter(java.lang.Object obj,
                  DataSource dataSource,
                  boolean dropExtraFields)
Creates a new JSONFilter. The set of properties to keep is defined by the set of fields defined on a DataSource. This constructor applies a DataSourceBeanFilter to the object.
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.
See Also:
DataSourceBeanFilter

JSONFilter

public JSONFilter(java.lang.Object obj,
                  java.util.Collection propsToKeep)
Creates a new JSONFilter. This constructor applies a KeepPropertiesFilter to the object.
Parameters:
obj - The object to serialize
propsToKeep - properties to keep.
See Also:
KeepPropertiesBeanFilter

JSONFilter

public JSONFilter(java.lang.Object obj,
                  java.lang.Object[] propsToKeep)
Creates a new JSONFilter. This constructor applies a KeepPropertiesFilter to the object.
Parameters:
obj - The object to serialize
propsToKeep - properties to keep.
See Also:
KeepPropertiesBeanFilter

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