Get single or one line exception message from exception object in Java

Response.status(BAD_REQUEST).entity(ex.getCause().getMessage()).build();

Using exceptionObject.getCause().getMessage() will give us the single or one line error message.

This is very useful when you want to show the exact one line message to the user.