This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
You should only use classes that can be mapped to XML Schema types, as per the WSDL specification. That will ensure that your Java WS are interoperable with other WS developed using different technologies.
So, using just any old Java class (serializable or not) won't do, unless you have written a custom serializer/deserializer that creates XML from it.
You can use the Java Beans XML Encoder/Decoder API to produce a XML file which represents your Java Object, if it meets the Java Beans specification. This is similar to normal Serilization with java.io.Serializable.
But please note that your class should adhere to Java Beans requirements. XML Encoder/Decoder API can be found at java.beans.*;
Other option is to use a JAXB Implementation. But in this case, you will have to write a XSD (XML Schema Definition) and use the JAXB Binding Compiler to build the classes from the XSD. This article about JAXB 2.0 gives the basics of JAXB 2.0.
Once you got the XML from the object, you can easily return the XML from your Web Service method.
(You will need the class file at the client-side to De-Serialize the XML). [ October 07, 2007: Message edited by: Yohan Liyanage ]