Could some pretty please comment on the following example code:
@XmlRootElement
@XmlTransient
public class SomeException extends RuntimeException {
@XmlTransient
private StackTraceElement[] stackTrace;
@XmlTransient
private transient Object backtrace;
@XmlTransient
private Throwable cause;
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();
}
@XmlTransient
@Override
public Throwable getCause() {
return super.getCause();
}
}
public class Main {
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);
}
}
}
I try every combination with @XmlTransistent but I always get:
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.SomeException
at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:91)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:436)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:277)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1100)
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:143)
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:110)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:222)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:396)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:594)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:542)
at jaxbtest.Main.main(Main.java:22)
em I doing something wrong or should I file this as a bug report ?
--
Adam Walczak
www.adamwalczak.info
+48 604 188 992