users@jaxb.java.net

Marshalling a superclass

From: joshua1970 <joshua1970j_at_libero.it>
Date: Fri, 6 Mar 2009 03:27:38 -0800 (PST)

Hi all !
I'm pretty new to JAXB, however I'm using just the basic features to marshal
my Entity Beans
into XML. This method works fine to marshal my EntityBean called "MyEntity"
into XML.

                StringWriter strWriter = new StringWriter();
                JAXBContext context = null;
                Marshaller marshaller = null;
                try {
                        context = JAXBContext.newInstance(BaseComponent.class);
                        marshaller = context.createMarshaller();
                        marshaller.setProperty( Marshaller.JAXB_FRAGMENT, Boolean.TRUE );
                } catch (JAXBException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                }
                Iterator <MyEntity> iter = list.iterator();
                while (iter.hasNext()) {
                        try {
                                MyEntity ejb = iter.next();
                                marshaller.marshal(ejb , strWriter);

                        } catch (JAXBException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
                }

My question is : how can I adapt this to all my Entity Beans ? I have tried
first adding a top interface to all my Entity Beans and replacing all
MyEntity with MyEntityItf in the code

ex
Iterator <MyEntity> iter = list.iterator();
with
Iterator <MyEntityItf> iter = list.iterator();

However I get a runtime error which warns me that I cannot use interfaces
with JAXB.
Ok, I have tried extending an empty Class as placeorder but I get an empty
XML and the error message:

[com.sun.istack.SAXException2: unable to marshal type "ejb.entity.MyEntity"
as an element because it is missing an @XmlRootElement annotation]

Can anybody give me a clue how to solve this problem ?
thanks a lot
john


-- 
View this message in context: http://www.nabble.com/Marshalling-a-superclass-tp22369487p22369487.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.