users@jaxb.java.net

Re: XmlElementRef points to a non-existent class

From: harinair <hari_g_at_hotmail.com>
Date: Thu, 5 Mar 2009 21:35:18 -0800 (PST)

Mich:

I don't know whether you found a solution or work-around for your problem
but I also came across the exact same problem and could not find any
solution to this. Finally with trial and error I came up with one. It seems
that the XmlElementRef documentation is wrong. You need to refer all
subclasses of the abstract class or interface where the XmlElementRef is
applied. The following example given in Javadoc will only if we do:

     @XmlRootElement(name="target")
     class Target {
         // The presence of @XmlElementRef indicates that the XML
         // element name will be derived from the @XmlRootElement
         // annotation on the type (for e.g. "jar" for JarTask).

         // Added by Hari - it will work only if the Ref points to
         // the concrete classes referred by the Interface or Abstract class
Task
         @XmlElementRefs({
                @XmlElementRef(type=JarTask.class),
                @XmlElementRef(type=JavacTask.class)
         })
         List<Task> tasks;
     }

     abstract class Task {
     }

     @XmlRootElement(name="jar")
     class JarTask extends Task {
         ...
     }

     @XmlRootElement(name="javac")
     class JavacTask extends Task {
         ...
     }



Hope this helps someone else even if it did not help you Mitch...

Hari Gangadharan



Mitch Claborn wrote:
>
> I'm trying to use @XmlElementRef to get a collection of objects with a
> common parent class, very similar to the Ant example in the doc:
> https://jaxb.dev.java.net/nonav/2.1.6/docs/api/javax/xml/bind/annotation/XmlElementRef.html
>
> For now, not using a schema - although I will once I get past this hurdle.
>
> The code compiles OK, but at runtime I get
>
> com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of
> IllegalAnnotationExceptions
> XmlElementRef points to a non-existent class.
> this problem is related to the following location:
> at private java.util.List com.csc.survey.Page.questionObjects
> at com.csc.survey.Page
> at private java.util.Vector com.csc.survey.PageLoop.pages
> at com.csc.survey.PageLoop
> at private java.util.Vector com.csc.survey.Section.pageLoops
> at com.csc.survey.Section
> at private java.util.Vector com.csc.survey.Survey.sections
> at com.csc.survey.Survey
>
>
> Code fragments:
>
> @XmlAccessorType(XmlAccessType.NONE)
> @XmlType(name="page")
> @XmlRootElement(name="page")
> public class Page implements Routable, Cloneable {
> @XmlElementRef
> private List<QuestionObject> questionObjects;
>
>
> abstract public class QuestionObject {
> public QuestionObject() {
> }
> }
>
>
> @XmlAccessorType(XmlAccessType.NONE)
> @XmlRootElement(name="question")
> public class Question extends QuestionObject implements Cloneable,
> Sequencable {
>
>
>
> --
> Mitch Claborn
> mitch_at_claborn.net
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>
>

-- 
View this message in context: http://www.nabble.com/XmlElementRef-points-to-a-non-existent-class-tp15191895p22366506.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.