Jersey's readEntity is serializing my Exceptions into java.lang.Throwable instead of the correct Error exception

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Jersey's readEntity is serializing my Exceptions into java.lang.Throwable instead of the correct Error exception

nddipiazza
This post has NOT been accepted by the mailing list yet.
In my code I have an Exception that extends IllegalArgumentException:

public class InvalidDataSourceException extends IllegalArgumentException {
  public InvalidDataSourceException(String message, Throwable cause) {
    super(message, cause);
  }
}

And in my Jersey REST web service, all errors are wrapped with a class RESTError so that all rest services can throw this same exception:

public class RESTError extends Throwable {
    public RESTError(Throwable cause) {
        super(cause);
    }
}

So when the InvalidDataSourceException occurs, it is thrown as the cause of a RESTError:

throw new RESTError(invalidDataSourceException);

Then from another Java app, I call create a jersey client and call this service method, triggering the REST Error. Upon reading error status I attempt to readEntity(RESTError.class).

When I do this, the Exception cause is serialized to java.lang.Throwable, instead of my custom InvalidDataSourceException. It down-casted it. Why is that?
Loading...