Package org.apache.struts2.json

# Class JSONInterceptor

java.lang.Object
org.apache.struts2.interceptor.AbstractInterceptor
org.apache.struts2.json.JSONInterceptor

All Implemented Interfaces:
  `Serializable`, `ConditionalInterceptor`, `Interceptor`

public class JSONInterceptor extends AbstractInterceptor
Populates an action from a JSON string

See Also:
  - Serialized Form

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `JSONInterceptor()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected String`
  `addCallbackIfApplicable(jakarta.servlet.http.HttpServletRequest request, String json)`
  `String`
  `getCallbackParameter()`
  `boolean`
  `getDebug()`
  `protected List`
  `getIncludeProperties()`
  `String`
  `intercept(ActionInvocation invocation)`
  `RPCResponse`
  `invoke(Object object, Map data)`
  `boolean`
  `isEnableGZIP()`
  `boolean`
  `isEnableSMD()`
  `boolean`
  `isExcludeNullProperties()`
  `boolean`
  `isNoCache()`
  `protected String`
  `readContentType(jakarta.servlet.http.HttpServletRequest request)`
  `protected String`
  `readContentTypeEncoding(jakarta.servlet.http.HttpServletRequest request)`
  `void`
  `setCallbackParameter(String callbackParameter)`
  `void`
  `setDebug(boolean debug)`
  Turns debugging on or off
  `void`
  `setDefaultEncoding(String val)`
  `void`
  `setDevMode(String mode)`
  `void`
  `setEnableGZIP(boolean enableGZIP)`
  Setting this property to "true" will compress the output.
  `void`
  `setEnableSMD(boolean enableSMD)`
  `void`
  `setExcludeNullProperties(boolean excludeNullProperties)`
  `void`
  `setExcludeProperties(String commaDelim)`
  Sets a comma-delimited list of regular expressions to match properties that should be excluded from the JSON output.
  `void`
  `setExcludeWildcards(String commaDelim)`
  Sets a comma-delimited list of wildcard expressions to match properties that should be excluded from the JSON output.
  `void`
  `setIgnoreHierarchy(boolean ignoreHierarchy)`
  `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(String commaDelim)`
  Sets a comma-delimited list of regular expressions to match properties that should be included from the JSON output.
  `void`
  `setIncludeWildcards(String commaDelim)`
  Sets a comma-delimited list of wildcard expressions to match properties that should be included from the JSON output.
  `void`
  `setJSONCleaner(JSONCleaner dataCleaner)`
  Sets the JSONCleaner to be used
  `void`
  `setJsonContentType(String jsonContentType)`
  `void`
  `setJSONPopulator(JSONPopulator populator)`
  Sets the JSONPopulator to be used
  `void`
  `setJsonRpcContentType(String jsonRpcContentType)`
  `void`
  `setNoCache(boolean noCache)`
  Add headers to response to prevent the browser from caching the response
  `void`
  `setPrefix(boolean prefix)`
  `void`
  `setRoot(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 org.apache.struts2.interceptor.AbstractInterceptor

  `destroy, init, setDisabled, shouldIntercept`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### JSONInterceptor

    public JSONInterceptor()

- ## Method Details

  - ### intercept

    public String intercept(ActionInvocation invocation) throws Exception
    Specified by:
      `intercept` in interface `Interceptor`
    Specified by:
      `intercept` in class `AbstractInterceptor`
    Throws:
      `Exception`

  - ### readContentType

    protected String readContentType(jakarta.servlet.http.HttpServletRequest request)

  - ### readContentTypeEncoding

    protected String readContentTypeEncoding(jakarta.servlet.http.HttpServletRequest request)

  - ### invoke

    public RPCResponse invoke(Object object, Map data) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, JSONException, InstantiationException, NoSuchMethodException, IntrospectionException
    Throws:
      `IllegalArgumentException`
      `IllegalAccessException`
      `InvocationTargetException`
      `JSONException`
      `InstantiationException`
      `NoSuchMethodException`
      `IntrospectionException`

  - ### addCallbackIfApplicable

    protected String addCallbackIfApplicable(jakarta.servlet.http.HttpServletRequest request, 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
    Parameters:
      `ignoreSMDMethodInterfaces` - set the flag for ignore SMD method interfaces

  - ### setWrapWithComments

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

  - ### setDefaultEncoding

    public void setDefaultEncoding(String val)

  - ### setIgnoreHierarchy

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

  - ### setRoot

    public void setRoot(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()
    Returns:
      true if debugging is turned on

  - ### setDebug

    public void setDebug(boolean debug)
    Turns debugging on or off
    Parameters:
      `debug` - true or false

  - ### setDevMode

    public void setDevMode(String mode)

  - ### setExcludeProperties

    public void setExcludeProperties(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

  - ### setExcludeWildcards

    public void setExcludeWildcards(String commaDelim)
    Sets a comma-delimited list of wildcard expressions to match properties that should be excluded from the JSON output.
    Parameters:
      `commaDelim` - A comma-delimited list of wildcard expressions

  - ### setIncludeProperties

    public void setIncludeProperties(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

  - ### setIncludeWildcards

    public void setIncludeWildcards(String commaDelim)
    Sets a comma-delimited list of wildcard expressions to match properties that should be included from the JSON output. The standard boilerplate (id, error, debug) are automatically included, as appropriate, so you only need to provide patterns for the contents of "result".
    Parameters:
      `commaDelim` - A comma-delimited list of wildcard expressions

  - ### getIncludeProperties

    protected List getIncludeProperties()
    Returns:
      the appropriate set of includes, based on debug setting. Derived classes can override if there are additional, custom debug-only parameters.

  - ### 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` - no cache

  - ### isExcludeNullProperties

    public boolean isExcludeNullProperties()

  - ### setExcludeNullProperties

    public void setExcludeNullProperties(boolean excludeNullProperties)
    Parameters:
      `excludeNullProperties` - Do not serialize properties with a null value

  - ### setCallbackParameter

    public void setCallbackParameter(String callbackParameter)

  - ### getCallbackParameter

    public String getCallbackParameter()

  - ### setPrefix

    public void setPrefix(boolean prefix)
    Parameters:
      `prefix` - Add "{} && " to generated JSON

  - ### setJsonContentType

    public void setJsonContentType(String jsonContentType)

  - ### setJsonRpcContentType

    public void setJsonRpcContentType(String jsonRpcContentType)