JAX-WS uses JAXB for mapping types, so classes must conform to this specification. You can find JAXB annotations in the java.xml.bind.annotations package.
If you want to marshal a non-annotated class, you must comply with the JavaBeans rules:
public class Foo { private String bar; public String getBar() { return bar; } public void setBar(String bar) { this.bar = bar; } public static void main(String[] args) { Foo foo = new Foo(); foo.setBar("Hello, World!"); ByteArrayOutputStream out = new ByteArrayOutputStream(); JAXB.marshal(foo, out); foo = (Foo) JAXB.unmarshal(new ByteArrayInputStream(out.toByteArray()), Foo.class); System.out.println(foo.getBar()); } }
If you want to use constructors with arguments, etc., take a look at the spec parts about factory methods and adapters.
Mcdowell
source share