tags:

views:

825

answers:

1

Hello

I have my own domain model and corresponding XSD schema for it. It consists of data types and messages that are exchanged in my application. I use XJC tool from Java JRE 1.5 for generation of Java classes for the given XSD schema. The generated classes do not contain neither the serialization/deserialization method nor the validation code. How can I achieve this using JAXB?

Regards

+2  A: 

Are you using JAXB 1.x or 2.x?

If 2.x then validation is built in. See this article.

Do you mean that you just want the code to marshall the Bean to XML and unmarshall the XML to a Bean?

There are many articles that show this. Here's an example of marshalling a bean into xml:

JAXBContext jaxb = JAXBContext.newInstance(MyBean.class);
Marshaller marshaller = jaxb.createMarshaller();
java.io.StringWriter sw = new StringWriter();
marshaller.marshal(myBean, sw);
System.out.println(sw.toString());
Damo
Thank you. It works. I'm new to Java so sorry for unconvienence.
dominolog
No inconvenience at all. It's what this site is for !
Damo