users@jaxb.java.net

Re: Trying to Marshal a Java Exception subclass

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Mon, 30 Jul 2007 13:50:25 -0700

JAXB is fairly limited when it comes to trying to bind existing 3rd
party classes that you cannot annotate. Exception is one such case.

I don't think it's possible to map Exception today. There's some ideas
floating around to make this kind of situation better, though...

Sean Landis wrote:
> 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?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>


-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com