Witam.
Mam sobie prosty wyjątek, który chciałbym zapisać do XML'a:
public class Main {
@XmlRootElement
static public class SomeException extends RuntimeException {
private Integer someAdditionalInformation;
public SomeException() {
}
public SomeException(Integer someAdditionalInformation) {
this.someAdditionalInformation = someAdditionalInformation;
}
public Integer getSomeAdditionalInformation() {
return someAdditionalInformation;
}
public void setSomeAdditionalInformation(
Integer someAdditionalInformation) {
this.someAdditionalInformation = someAdditionalInformation;
}
@XmlTransient
@Override
public StackTraceElement[] getStackTrace() {
return super.getStackTrace();
}
}
public static void main(String[] args) {
try {
JAXBContext jaxbCtx = JAXBContext.newInstance(SomeException.class);
Marshaller m = jaxbCtx.createMarshaller();
m.marshal(new SomeException(5), System.out);
} catch (JAXBException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
Ale dostaje wyjątek typu:
com.sun.xml.internal.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 java.lang.RuntimeException
at jaxbtest.Main$SomeException
Czy to pachnie bugiem w JAXB ?
@XmlTransient powinien sprawić że JAXB w ogóle nie będzie się interesował tym atrybutem
Wie ktoś może jak obejść ten problem ?