I have an XmlJavaTypeAdapter
defined for each Exception in my exception heirarchy. I use a wrapper object for marshaling the exceptions as below:-
@XmlRootElement
public Wrapper<T extends BaseException> {
T exception;
}
The exceptions:-
@XmlJavaTypeAdapter(BaseExceptionAdapter.class) {
public class BaseException extends RuntimeException {
}
@XmlJavaTypeAdapter(DerivedExceptionAdapter.class) {
public class DerivedException extends BaseException {
}
When I try marshaling a wrapper object, JAXB by default always calls the BaseExceptionAdapter
even if the actual exception is of type DerivedException
. How can I force it to look for the instance type of the exception rather than the reference type.
Just to add, package-info
/ jaxb.index
etc are as excepted.