Article: Generate an XML Document from an Object Model with JAXB 2

I‘ve just published an article about JAXB 2 on DevX web site. JAXB (Java Architecture for XML Binding) allows you to perform XML-to-Java data binding and generate Java classes from XML schemas and vice-versa. But in this article I mainly focus on marshalling (generate XML from Java objects). You will see how easy it is to generate XML without doing much (thanks to coding by exception). Then, I introduce a set of annotations that enable to customize the XML mapping.

At the end of the article I make a reference to two other articles I wrote on JPA. Because I’ve used the same object model on all articles, I give an example of a class that can be persisted in a database using JPA annotations and binds to XML using JAXB annotations. As I’ve blogged before, this over used of annotations can be dangerous because code gets pretty messy. If you have specific needs, it‘s good to know that you can do it (JPA & JAXB in the same class). Otherwise, you should focus on modeling your classes with the right responsabilities.

Categories: Java

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s