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.
Looks like you need an @XmlElementRef on your T field, to tell JAXB to look that up dynamically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With