How to validate JSON being sent using Struts2 JSON Plugin without throwing exception How to validate JSON being sent using Struts2 JSON Plugin without throwing exception json json

How to validate JSON being sent using Struts2 JSON Plugin without throwing exception


You could place exception interceptor before your own interceptor instead of the json interceptor by extending json interceptor and override intercept method where you can catch errors. Then you can either add action errors or rethrow a custom exception which you can map in the action config or globally.

<exception-mapping exception="org.exceptionmapping.CustomException"                             result="errorresult"/>

This way you can map all json only interceptor errors with your custom exception.