users@jaxb.java.net

Failing with 'no-arg default constructor' on _at_XmlTransient

From: Adam Walczak <me_at_adamwalczak.info>
Date: Mon, 13 Dec 2010 10:18:10 +0100

Hello,

I have a simple exception I want to serialize to xml like this:

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);
}
}

}


But I get the following exception:


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


Does this seam like a JAXB bug ?
@XmlTransient should make JAXB just skip that property.

Is there ant way to workaround this ?

-- 
Adam Walczak
www.adamwalczak.info
+48 604 188 992