cubesoft
cubesoft

Reputation: 3550

Java JAXB XJC code generation form XSD schema problem

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

Upvotes: 0

Views: 2564

Answers (1)

Damo
Damo

Reputation: 11550

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());

Upvotes: 4

Related Questions