users@jaxb.java.net

Multiple objects which are root elements in the same package

From: Alan Chaney <alan_at_muzlink.com>
Date: Fri, 17 Apr 2009 09:05:25 -0700

Hi

This is a complete newb question. I've just started using Jaxb 2.1 and
am very impressed. I'm trying to use jaxb to marshal/unmarshal a number
of objects where under certain circumstances different objects in the
object graph are the root element.

A simple illustration for objects A, B and C where

A has a list of B
and B has a list of C

is that in some cases I want A to be the root, some cases B to be the
root and some cases C to be the root.

Experimentation indicates that simply setting @XMLRootElement
annotations in the classes A B and C works.

The problem is that if I regenerate the schema using xjc only the 'root'
element of the schema gets that annotation.

Is there any easy way to organize or indicate within the schema that A B
and C should all be marked with @XmlRootElement so I don't have to keep
manually editing the source files after compilation?

Once again, I apologize if the answer is obvious in the docs but I
couldn't find it.

Thanks in advance

Alan Chaney