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

前端 未结 1 1114
[愿得一人]
[愿得一人] 2021-01-06 17:21

Suppose there\'s a Double variable in an action, and if the value sent in the request body is something like

{\"dblField\":\"\"}
相关标签:
1条回答
  • 2021-01-06 17:58

    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.

    0 讨论(0)
提交回复
热议问题