mercredi 25 mars 2015

Spring Controller return broken JSON string to Client

I have added a Controller Advice to handle all exceptions in application at one place, including a @Throwable method handler. In exception handler method I want to add some information into exception object and return exception object to Client. I expect error handler at client to receive exception object JSON and based on error code a module in application or $(doc).ajaxError global handler can display exception message. Everything works fine for most cases except for a case. When UnrecognizedPropertyException is caught in Exception Handler method, it returns broken JSON to client and simply it could not converted to JSON object at client. Why the JSON returned in this case is incomplete and how could I handle this situation to return normal exception object only?


Note-


The exception is caught into @Throwable exception handler.


Returned JSON contains the OBJECT for which the JSON conversion failed in broken format.


Aucun commentaire:

Enregistrer un commentaire