public class JSONResult extends Object implements Result
This result serializes an action into JSON.
Result parameters:
Example:
<!-- START SNIPPET: example --> <result name="success" type="json" /> <!-- END SNIPPET: example -->
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_PARAM
This result type doesn't have a default param, null is ok to reduce noise in logs
|
Constructor and Description |
---|
JSONResult() |
Modifier and Type | Method and Description |
---|---|
protected String |
addCallbackIfApplicable(javax.servlet.http.HttpServletRequest request,
String json) |
protected SMD |
buildSMDObject(ActionInvocation invocation) |
protected String |
createJSONString(javax.servlet.http.HttpServletRequest request,
Object rootObject) |
protected boolean |
enableGzip(javax.servlet.http.HttpServletRequest request) |
void |
execute(ActionInvocation invocation) |
protected Object |
findRootObject(ActionInvocation invocation) |
String |
getCallbackParameter() |
String |
getDefaultDateFormat() |
protected String |
getEncoding()
Retrieve the encoding
|
List<Pattern> |
getExcludePropertiesList()
Gets a list of regular expressions of properties to exclude from the JSON
output.
|
List<Pattern> |
getIncludePropertiesList() |
String |
getRoot() |
String |
getWrapPrefix() |
String |
getWrapSuffix() |
boolean |
isEnableGZIP() |
boolean |
isEnableSMD() |
boolean |
isEnumAsBean() |
boolean |
isExcludeNullProperties() |
boolean |
isIgnoreHierarchy() |
boolean |
isNoCache() |
boolean |
isWrapWithComments() |
protected Object |
readRootObject(ActionInvocation invocation) |
void |
setCallbackParameter(String callbackParameter) |
void |
setContentType(String contentType) |
void |
setDefaultDateFormat(String defaultDateFormat) |
void |
setDefaultEncoding(String val) |
void |
setDevMode(String val) |
void |
setEnableGZIP(boolean enableGZIP) |
void |
setEnableSMD(boolean enableSMD) |
void |
setEncoding(String encoding)
If defined will be used instead of
defaultEncoding , you can define it with result
<result name="success" type="json">
<param name="encoding">UTF-8</param>
</result> |
void |
setEnumAsBean(boolean enumAsBean) |
void |
setErrorCode(int errorCode) |
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 |
setIgnoreInterfaces(boolean ignoreInterfaces) |
void |
setIncludeProperties(String commaDelim)
Sets a comma-delimited list of regular expressions to match properties
that should be included in the JSON output.
|
void |
setIncludeWildcards(String commaDelim)
Sets a comma-delimited list of wildcard expressions to match properties
that should be included in the JSON output.
|
void |
setJsonUtil(JSONUtil jsonUtil) |
void |
setNoCache(boolean noCache) |
void |
setPrefix(boolean prefix) |
void |
setRoot(String root)
Sets the root object to be serialized, defaults to the Action
|
void |
setStatusCode(int statusCode) |
void |
setWrapPrefix(String wrapPrefix) |
void |
setWrapSuffix(String wrapSuffix) |
void |
setWrapWithComments(boolean wrapWithComments) |
protected void |
writeToResponse(javax.servlet.http.HttpServletResponse response,
String json,
boolean gzip) |
public static final String DEFAULT_PARAM
public void setDefaultEncoding(String val)
public void setDevMode(String val)
public void setJsonUtil(JSONUtil jsonUtil)
public List<Pattern> getExcludePropertiesList()
public void setExcludeProperties(String commaDelim)
commaDelim
- A comma-delimited list of regular expressionspublic void setExcludeWildcards(String commaDelim)
commaDelim
- A comma-delimited list of wildcard patternspublic List<Pattern> getIncludePropertiesList()
public void setIncludeProperties(String commaDelim)
commaDelim
- A comma-delimited list of regular expressionspublic void setIncludeWildcards(String commaDelim)
commaDelim
- A comma-delimited list of wildcard patternspublic void execute(ActionInvocation invocation) throws Exception
protected Object readRootObject(ActionInvocation invocation)
protected Object findRootObject(ActionInvocation invocation)
protected String createJSONString(javax.servlet.http.HttpServletRequest request, Object rootObject) throws JSONException
JSONException
protected boolean enableGzip(javax.servlet.http.HttpServletRequest request)
protected void writeToResponse(javax.servlet.http.HttpServletResponse response, String json, boolean gzip) throws IOException
IOException
protected SMD buildSMDObject(ActionInvocation invocation)
protected String getEncoding()
protected String addCallbackIfApplicable(javax.servlet.http.HttpServletRequest request, String json)
public String getRoot()
public void setRoot(String root)
root
- OGNL expression of root object to be serializedpublic boolean isWrapWithComments()
public void setWrapWithComments(boolean wrapWithComments)
wrapWithComments
- Wrap generated JSON with commentspublic boolean isEnableSMD()
public void setEnableSMD(boolean enableSMD)
enableSMD
- Enable SMD generation for action, which can be used for JSON-RPCpublic void setIgnoreHierarchy(boolean ignoreHierarchy)
public void setIgnoreInterfaces(boolean ignoreInterfaces)
ignoreInterfaces
- Controls whether interfaces should be inspected for method annotations
You may need to set to this true if your action is a proxy as annotations
on methods are not inheritedpublic void setEnumAsBean(boolean enumAsBean)
enumAsBean
- Controls how Enum's are serialized : If true, an Enum is serialized as a
name=value pair (name=name()) (default) If false, an Enum is serialized
as a bean with a special property _name=name()public boolean isEnumAsBean()
public boolean isEnableGZIP()
public void setEnableGZIP(boolean enableGZIP)
public boolean isNoCache()
public void setNoCache(boolean noCache)
noCache
- Add headers to response to prevent the browser from caching the responsepublic boolean isIgnoreHierarchy()
public boolean isExcludeNullProperties()
public void setExcludeNullProperties(boolean excludeNullProperties)
excludeNullProperties
- Do not serialize properties with a null valuepublic void setStatusCode(int statusCode)
statusCode
- Status code to be set in the responsepublic void setErrorCode(int errorCode)
errorCode
- Error code to be set in the responsepublic void setCallbackParameter(String callbackParameter)
public String getCallbackParameter()
public void setPrefix(boolean prefix)
prefix
- Prefix JSON with "{} &&"public void setContentType(String contentType)
contentType
- Content type to be set in the responsepublic String getWrapPrefix()
public void setWrapPrefix(String wrapPrefix)
wrapPrefix
- Text to be inserted at the begining of the responsepublic String getWrapSuffix()
public void setWrapSuffix(String wrapSuffix)
wrapSuffix
- Text to be inserted at the end of the responsepublic void setEncoding(String encoding)
defaultEncoding
, you can define it with result
<result name="success" type="json">
<param name="encoding">UTF-8</param>
</result>encoding
- valid encoding stringpublic String getDefaultDateFormat()
public void setDefaultDateFormat(String defaultDateFormat)
Copyright © 2000–2020 Apache Software Foundation. All rights reserved.