org.apache.struts2.json
Class JSONInterceptor

java.lang.Object
  extended by org.apache.struts2.json.JSONInterceptor
All Implemented Interfaces:
com.opensymphony.xwork2.interceptor.Interceptor, java.io.Serializable

public class JSONInterceptor
extends java.lang.Object
implements com.opensymphony.xwork2.interceptor.Interceptor

Populates an action from a JSON string

See Also:
Serialized Form

Constructor Summary
JSONInterceptor()
           
 
Method Summary
protected  java.lang.String addCallbackIfApplicable(javax.servlet.http.HttpServletRequest request, java.lang.String json)
           
 void destroy()
           
 java.lang.String getCallbackParameter()
           
 boolean getDebug()
          Turns debugging on or off
 void init()
           
 java.lang.String intercept(com.opensymphony.xwork2.ActionInvocation invocation)
           
 RPCResponse invoke(java.lang.Object object, java.util.Map data)
           
 boolean isEnableGZIP()
           
 boolean isEnableSMD()
           
 boolean isExcludeNullProperties()
           
 boolean isNoCache()
           
 void setCallbackParameter(java.lang.String callbackParameter)
           
 void setContentType(java.lang.String contentType)
           
 void setDebug(boolean debug)
           
 void setDefaultEncoding(java.lang.String val)
           
 void setEnableGZIP(boolean enableGZIP)
          Setting this property to "true" will compress the output.
 void setEnableSMD(boolean enableSMD)
           
 void setExcludeNullProperties(boolean excludeNullProperties)
          Do not serialize properties with a null value
 void setExcludeProperties(java.lang.String commaDelim)
          Sets a comma-delimited list of regular expressions to match properties that should be excluded from the JSON output.
 void setIgnoreHierarchy(boolean ignoreHierarchy)
          Ignore properties defined on base classes of the root object.
 void setIgnoreSMDMethodInterfaces(boolean ignoreSMDMethodInterfaces)
          Ignore annotations on methods in interfaces You may need to set to this true if your action is a proxy/enhanced as annotations are not inherited
 void setIncludeProperties(java.lang.String commaDelim)
          Sets a comma-delimited list of regular expressions to match properties that should be included from the JSON output.
 void setJSONCleaner(JSONCleaner dataCleaner)
          Sets the JSONCleaner to be used
 void setJSONPopulator(JSONPopulator populator)
          Sets the JSONPopulator to be used
 void setNoCache(boolean noCache)
          Add headers to response to prevent the browser from caching the response
 void setPrefix(boolean prefix)
          Add "{} && " to generated JSON
 void setRoot(java.lang.String root)
          Sets the root object to be deserialized, defaults to the Action
 void setWrapWithComments(boolean wrapWithComments)
          Wrap generated JSON with comments.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSONInterceptor

public JSONInterceptor()
Method Detail

destroy

public void destroy()
Specified by:
destroy in interface com.opensymphony.xwork2.interceptor.Interceptor

init

public void init()
Specified by:
init in interface com.opensymphony.xwork2.interceptor.Interceptor

intercept

public java.lang.String intercept(com.opensymphony.xwork2.ActionInvocation invocation)
                           throws java.lang.Exception
Specified by:
intercept in interface com.opensymphony.xwork2.interceptor.Interceptor
Throws:
java.lang.Exception

invoke

public RPCResponse invoke(java.lang.Object object,
                          java.util.Map data)
                   throws java.lang.IllegalArgumentException,
                          java.lang.IllegalAccessException,
                          java.lang.reflect.InvocationTargetException,
                          JSONException,
                          java.lang.InstantiationException,
                          java.lang.NoSuchMethodException,
                          java.beans.IntrospectionException
Throws:
java.lang.IllegalArgumentException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
JSONException
java.lang.InstantiationException
java.lang.NoSuchMethodException
java.beans.IntrospectionException

addCallbackIfApplicable

protected java.lang.String addCallbackIfApplicable(javax.servlet.http.HttpServletRequest request,
                                                   java.lang.String json)

isEnableSMD

public boolean isEnableSMD()

setEnableSMD

public void setEnableSMD(boolean enableSMD)

setIgnoreSMDMethodInterfaces

public void setIgnoreSMDMethodInterfaces(boolean ignoreSMDMethodInterfaces)
Ignore annotations on methods in interfaces You may need to set to this true if your action is a proxy/enhanced as annotations are not inherited


setWrapWithComments

public void setWrapWithComments(boolean wrapWithComments)
Wrap generated JSON with comments. Only used if SMD is enabled.

Parameters:
wrapWithComments -

setDefaultEncoding

public void setDefaultEncoding(java.lang.String val)

setIgnoreHierarchy

public void setIgnoreHierarchy(boolean ignoreHierarchy)
Ignore properties defined on base classes of the root object.

Parameters:
ignoreHierarchy -

setRoot

public void setRoot(java.lang.String root)
Sets the root object to be deserialized, defaults to the Action

Parameters:
root - OGNL expression of root object to be serialized

setJSONPopulator

public void setJSONPopulator(JSONPopulator populator)
Sets the JSONPopulator to be used

Parameters:
populator - JSONPopulator

setJSONCleaner

public void setJSONCleaner(JSONCleaner dataCleaner)
Sets the JSONCleaner to be used

Parameters:
dataCleaner - JSONCleaner

getDebug

public boolean getDebug()
Turns debugging on or off

Parameters:
debug - true or false

setDebug

public void setDebug(boolean debug)

setExcludeProperties

public void setExcludeProperties(java.lang.String commaDelim)
Sets a comma-delimited list of regular expressions to match properties that should be excluded from the JSON output.

Parameters:
commaDelim - A comma-delimited list of regular expressions

setIncludeProperties

public void setIncludeProperties(java.lang.String commaDelim)
Sets a comma-delimited list of regular expressions to match properties that should be included from the JSON output.

Parameters:
commaDelim - A comma-delimited list of regular expressions

isEnableGZIP

public boolean isEnableGZIP()

setEnableGZIP

public void setEnableGZIP(boolean enableGZIP)
Setting this property to "true" will compress the output.

Parameters:
enableGZIP - Enable compressed output

isNoCache

public boolean isNoCache()

setNoCache

public void setNoCache(boolean noCache)
Add headers to response to prevent the browser from caching the response

Parameters:
noCache -

isExcludeNullProperties

public boolean isExcludeNullProperties()

setExcludeNullProperties

public void setExcludeNullProperties(boolean excludeNullProperties)
Do not serialize properties with a null value

Parameters:
excludeNullProperties -

setCallbackParameter

public void setCallbackParameter(java.lang.String callbackParameter)

getCallbackParameter

public java.lang.String getCallbackParameter()

setPrefix

public void setPrefix(boolean prefix)
Add "{} && " to generated JSON

Parameters:
prefix -

setContentType

public void setContentType(java.lang.String contentType)


Copyright © 2000-2009 Apache Software Foundation. All Rights Reserved.