Package org.apache.struts2.json

# Class JSONValidationInterceptor

java.lang.Object
org.apache.struts2.interceptor.AbstractInterceptor
org.apache.struts2.interceptor.MethodFilterInterceptor
org.apache.struts2.json.JSONValidationInterceptor

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

public class JSONValidationInterceptor extends MethodFilterInterceptor
Serializes validation and action errors into JSON. This interceptor does not perform any validation, so it must follow the 'validation' interceptor on the stack.

See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `DEFAULT_ENCODING`
  `static final String`
  `NO_ENCODING_SET_PARAM`
  `static final String`
  `VALIDATE_JSON_PARAM`
  `static final String`
  `VALIDATE_ONLY_PARAM`

  ### Fields inherited from class org.apache.struts2.interceptor.MethodFilterInterceptor

  `excludeMethods, includeMethods`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `JSONValidationInterceptor()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected String`
  `buildResponse(ValidationAware validationAware)`
  `protected String`
  `doIntercept(ActionInvocation invocation)`
  `boolean`
  `isJsonEnabled(jakarta.servlet.http.HttpServletRequest request)`
  `boolean`
  `isSetEncoding(jakarta.servlet.http.HttpServletRequest request)`
  `boolean`
  `isValidateOnly(jakarta.servlet.http.HttpServletRequest request)`
  `void`
  `setNoEncodingSetParam(String noEncodingSetParam)`
  Overrides 'struts.JSONValidation.no.encoding' param name
  `void`
  `setValidateJsonParam(String validateJsonParam)`
  Overrides 'struts.enableJSONValidation' param name
  `void`
  `setValidateOnlyParam(String validateOnlyParam)`
  Overrides 'struts.validateOnly' param name
  `void`
  `setValidationFailedStatus(int validationFailedStatus)`
  HTTP status that will be set in the response if validation fails

  ### Methods inherited from class org.apache.struts2.interceptor.MethodFilterInterceptor

  `applyInterceptor, getExcludeMethodsSet, getIncludeMethodsSet, intercept, setExcludeMethods, setIncludeMethods`

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

- ## Field Details

  - ### VALIDATE_ONLY_PARAM

    public static final String VALIDATE_ONLY_PARAM
    See Also:
      - Constant Field Values

  - ### VALIDATE_JSON_PARAM

    public static final String VALIDATE_JSON_PARAM
    See Also:
      - Constant Field Values

  - ### NO_ENCODING_SET_PARAM

    public static final String NO_ENCODING_SET_PARAM
    See Also:
      - Constant Field Values

  - ### DEFAULT_ENCODING

    public static final String DEFAULT_ENCODING
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### JSONValidationInterceptor

    public JSONValidationInterceptor()

- ## Method Details

  - ### doIntercept

    protected String doIntercept(ActionInvocation invocation) throws Exception
    Specified by:
      `doIntercept` in class `MethodFilterInterceptor`
    Throws:
      `Exception`

  - ### isJsonEnabled

    public boolean isJsonEnabled(jakarta.servlet.http.HttpServletRequest request)

  - ### isValidateOnly

    public boolean isValidateOnly(jakarta.servlet.http.HttpServletRequest request)

  - ### isSetEncoding

    public boolean isSetEncoding(jakarta.servlet.http.HttpServletRequest request)

  - ### buildResponse

    protected String buildResponse(ValidationAware validationAware)
    Parameters:
      `validationAware` - the validation aware object
    Returns:
      JSON string that contains the errors and field errors

  - ### setValidationFailedStatus

    public void setValidationFailedStatus(int validationFailedStatus)
    HTTP status that will be set in the response if validation fails
    Parameters:
      `validationFailedStatus` - validation failed status

  - ### setValidateOnlyParam

    public void setValidateOnlyParam(String validateOnlyParam)
    Overrides 'struts.validateOnly' param name
    Parameters:
      `validateOnlyParam` - new param name

  - ### setValidateJsonParam

    public void setValidateJsonParam(String validateJsonParam)
    Overrides 'struts.enableJSONValidation' param name
    Parameters:
      `validateJsonParam` - new param name

  - ### setNoEncodingSetParam

    public void setNoEncodingSetParam(String noEncodingSetParam)
    Overrides 'struts.JSONValidation.no.encoding' param name
    Parameters:
      `noEncodingSetParam` - new param name