users@jaxb.java.net

Trying to Marshal a Java Exception subclass

From: Sean Landis <sean.landis_at_gmail.com>
Date: Mon, 23 Jul 2007 12:24:12 -0600

I would like to be able to marshal a class which is a subclass of
exception and I cannot figure a way to do that. Here's my code:

@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlRootElement(name = "MyException")
public class MyException extends Exception {
  public MyException() {
  }

  public MyException(String message) {
    super(message);
  }

  @XmlElement(name = "message")
  @Override public String getMessage() {
    return super.getMessage();
  }
}

When I try to convert this to XML I get the following runtime error:

WARNING: Problem creating Marshaller
com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of
IllegalAnnotationExceptions
java.lang.StackTraceElement does not have a no-arg default constructor.
this problem is related to the following location:
at java.lang.StackTraceElement
at public java.lang.StackTraceElement[] java.lang.Throwable.getStackTrace()
at java.lang.Throwable
at java.lang.Exception
at com.overstock.failures.MyException
at public com.overstock.failures.MyException
com.overstock.failures.ObjectFactory.createMyException()
at com.overstock.failures.ObjectFactory

In my object factory I have:

public MyException createMyException() {
  return new MyException();
}

Is there any way to do this?