jaxbtest.SomeException

Java.net JIRA | walec51 | 6 years ago
  1. 0

    Hello, I have a simple exception I want to serialize to xml like this: @XmlRootElement 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(); } @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); } } } As I understand the stack trace should be omitted because of the @XmlTransient annotation But I get the following exception: 2011-02-10 19:03:27 jaxbtest.Main main SEVERE: null 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)

    Java.net JIRA | 6 years ago | walec51
    jaxbtest.SomeException

    Root Cause Analysis

    1. jaxbtest.SomeException

      No message provided

      at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check()
    2. Java RT
      JAXBContext.newInstance
      1. com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:91)
      2. com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:436)
      3. com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:277)
      4. com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1100)
      5. com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:143)
      6. com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:110)
      7. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      8. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      9. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      10. java.lang.reflect.Method.invoke(Method.java:616)
      11. javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:222)
      12. javax.xml.bind.ContextFinder.find(ContextFinder.java:396)
      13. javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:594)
      14. javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:542)
      14 frames
    3. jaxbtest
      Main.main
      1. jaxbtest.Main.main(Main.java:22)
      1 frame