|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.isomorphic.js.JSONFilter
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.
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 |
public JSONFilter(java.lang.Object obj, java.lang.String dataSource, boolean dropExtraFields)
obj
- The object to serializedataSource
- The name of the dataSource from which to fetch field names for use as
the set of properties on the object to keep.DataSourceBeanFilter
public JSONFilter(java.lang.Object obj, DataSource dataSource, boolean dropExtraFields)
obj
- The object to serializedataSource
- The dataSource instance from which to fetch field names for use as
the set of properties on the object to keep.DataSourceBeanFilter
public JSONFilter(java.lang.Object obj, java.util.Collection propsToKeep)
obj
- The object to serializepropsToKeep
- properties to keep.KeepPropertiesBeanFilter
public JSONFilter(java.lang.Object obj, java.lang.Object[] propsToKeep)
obj
- The object to serializepropsToKeep
- properties to keep.KeepPropertiesBeanFilter
public JSONFilter(java.lang.Object obj, IBeanFilter beanFilter)
obj
- The object to serializepropsToKeep
- properties to keep.IBeanFilter
Method Detail |
public IBeanFilter getBeanFilter()
public java.lang.Object getObj()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |