Get path variable from HttpMessageNotReadable exception

We have some web services that are consumed by mobile clients, in which mobile clients make some kind of request, and we return a response to them. Somehow, if the client makes any invalid request, we throw Custom Exceptions.
But recently, a mobile client made some request that was out of range for a variable Long.
The client has different variables for ex ::

    {
      "accountId":"343"
      "Amount":"90909090909090909090"
    }

If the value of accountId or Amount is more than 19 digits, we get an exception HttpMessageNotReadable, because the range does not have a long value. But from the exception, I can’t get for which variable the exception was raised for accountIdor Amount. From the exception, I get this information in a variable _path, but I cannot extract it. enter image description here

And in the variable path, I get something like:

[com.Upload["AccountInfo"], com.Info["Account"]]

Does anyone know how to get this information.

+4
source share
1 answer

The following code displays a field that throws an exception.

InvalidFormatException invalidFormatException = (InvalidFormatException) exception
        .getCause();
System.out.println(invalidFormatException.getPath().get(0)
        .getFieldName());
+3
source

Source: https://habr.com/ru/post/1626295/


All Articles