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
Populates an action from a JSON string
- See Also:
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected StringaddCallbackIfApplicable(jakarta.servlet.http.HttpServletRequest request, String json) booleangetDebug()protected Listintercept(ActionInvocation invocation) booleanbooleanbooleanbooleanprotected StringreadContentType(jakarta.servlet.http.HttpServletRequest request) protected StringreadContentTypeEncoding(jakarta.servlet.http.HttpServletRequest request) voidsetCallbackParameter(String callbackParameter) voidsetDebug(boolean debug) Turns debugging on or offvoidsetDefaultEncoding(String val) voidsetDevMode(String mode) voidsetEnableGZIP(boolean enableGZIP) Setting this property to "true" will compress the output.voidsetEnableSMD(boolean enableSMD) voidsetExcludeNullProperties(boolean excludeNullProperties) voidsetExcludeProperties(String commaDelim) Sets a comma-delimited list of regular expressions to match properties that should be excluded from the JSON output.voidsetExcludeWildcards(String commaDelim) Sets a comma-delimited list of wildcard expressions to match properties that should be excluded from the JSON output.voidsetIgnoreHierarchy(boolean ignoreHierarchy) voidsetIgnoreSMDMethodInterfaces(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 inheritedvoidsetIncludeProperties(String commaDelim) Sets a comma-delimited list of regular expressions to match properties that should be included from the JSON output.voidsetIncludeWildcards(String commaDelim) Sets a comma-delimited list of wildcard expressions to match properties that should be included from the JSON output.voidsetJSONCleaner(JSONCleaner dataCleaner) Sets the JSONCleaner to be usedvoidsetJsonContentType(String jsonContentType) voidsetJSONPopulator(JSONPopulator populator) Sets the JSONPopulator to be usedvoidsetJsonRpcContentType(String jsonRpcContentType) voidsetNoCache(boolean noCache) Add headers to response to prevent the browser from caching the responsevoidsetPrefix(boolean prefix) voidSets the root object to be deserialized, defaults to the ActionvoidsetWrapWithComments(boolean wrapWithComments) Wrap generated JSON with comments.Methods inherited from class org.apache.struts2.interceptor.AbstractInterceptordestroy, init, setDisabled, shouldIntercept
- 
Constructor Details- 
JSONInterceptorpublic JSONInterceptor()
 
- 
- 
Method Details- 
intercept- Specified by:
- interceptin interface- Interceptor
- Specified by:
- interceptin class- AbstractInterceptor
- Throws:
- Exception
 
- 
readContentType
- 
readContentTypeEncoding
- 
invokepublic RPCResponse invoke(Object object, Map data) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, JSONException, InstantiationException, NoSuchMethodException, IntrospectionException 
- 
addCallbackIfApplicable
- 
isEnableSMDpublic boolean isEnableSMD()
- 
setEnableSMDpublic void setEnableSMD(boolean enableSMD) 
- 
setIgnoreSMDMethodInterfacespublic 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
 
- 
setWrapWithCommentspublic void setWrapWithComments(boolean wrapWithComments) Wrap generated JSON with comments. Only used if SMD is enabled.- Parameters:
- wrapWithComments- Wrap generated JSON with comments.
 
- 
setDefaultEncoding
- 
setIgnoreHierarchypublic void setIgnoreHierarchy(boolean ignoreHierarchy) - Parameters:
- ignoreHierarchy- Ignore properties defined on base classes of the root object.
 
- 
setRootSets the root object to be deserialized, defaults to the Action- Parameters:
- root- OGNL expression of root object to be serialized
 
- 
setJSONPopulatorSets the JSONPopulator to be used- Parameters:
- populator- JSONPopulator
 
- 
setJSONCleanerSets the JSONCleaner to be used- Parameters:
- dataCleaner- JSONCleaner
 
- 
getDebugpublic boolean getDebug()- Returns:
- true if debugging is turned on
 
- 
setDebugpublic void setDebug(boolean debug) Turns debugging on or off- Parameters:
- debug- true or false
 
- 
setDevMode
- 
setExcludePropertiesSets 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
 
- 
setExcludeWildcardsSets 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
 
- 
setIncludePropertiesSets 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
 
- 
setIncludeWildcardsSets 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- Returns:
- the appropriate set of includes, based on debug setting. Derived classes can override if there are additional, custom debug-only parameters.
 
- 
isEnableGZIPpublic boolean isEnableGZIP()
- 
setEnableGZIPpublic void setEnableGZIP(boolean enableGZIP) Setting this property to "true" will compress the output.- Parameters:
- enableGZIP- Enable compressed output
 
- 
isNoCachepublic boolean isNoCache()
- 
setNoCachepublic void setNoCache(boolean noCache) Add headers to response to prevent the browser from caching the response- Parameters:
- noCache- no cache
 
- 
isExcludeNullPropertiespublic boolean isExcludeNullProperties()
- 
setExcludeNullPropertiespublic void setExcludeNullProperties(boolean excludeNullProperties) - Parameters:
- excludeNullProperties- Do not serialize properties with a null value
 
- 
setCallbackParameter
- 
getCallbackParameter
- 
setPrefixpublic void setPrefix(boolean prefix) - Parameters:
- prefix- Add "{} && " to generated JSON
 
- 
setJsonContentType
- 
setJsonRpcContentType
 
-