users@jaxb.java.net

cannot adapt an XmlRootElement ?

From: Mark Hansen <mark_at_javector.com>
Date: Thu, 12 Jan 2006 15:40:59 -0500

It appears that you cannot get JAXB to adapt a root element class. So,
there is no way to marshal a bound type to a global element.

The spec requires a "point of reference" for the bound type. And when
the bound type is the root element class, then there is no point of
reference. This seems like a problem with the specification.

I.e., you should be able to do this (Foo is the value type and MyFoo is
the bound type):

@XmlRootElement
@XmlJavaTypeAdapter(MyFooAdapter.class)
public class MyFoo {
   ....
}


@XmlRootElement
public class Foo {
 ....
}


Given the above, when you marshal an instance of MyFoo, it should
produce the XML that is mapped from Foo. But, the Sun RI does not work
like this. It seems to ignore the adapter. It seems that this behavior
is consistent with the specification - since there is not "point of
reference" for MyFoo in the actual class definition of MyFoo. However,
the upshot is that you can't marshal a boutn type to a global element.
That seems like a common use case that JAXB 2.0 should handle.

Pleasse let me know if I am missing something.

-- Mark