users@jaxb.java.net

AW: Forcing xsi:type for non element marshalling

From: Ernst, Matthias <matthias.ernst_at_coremedia.com>
Date: Fri, 17 Nov 2006 16:03:11 +0100

From the URL you cite:

"
At the first glance the second Point.class parameter may look redundant,
but it's actually necessary to determine if the marshaller will produce
(infamous) @xsi:type. In this example, both the class and the instance
are Point, so you won't see @xsi:type. But if they are different, you'll
see it.
"

So

marshaller.marshal(
  new JAXBElement(
    new QName("","rootTag"),
    Object.class,
    new Point(3,5)
  )
);

should produce

<rootTag xsi:type="point" x="3" y="5"/>

Haven't tried it though ...


Matthias