Home > All Posts, Frameworks, How Tos, Java, Posts in English, Web Services > Walk through JAXB and JIBX

Walk through JAXB and JIBX

Most of the audience here might already have worked directly or indirectly (Web Services) with JAXB or JIBX. For those who want to develop or use Web Services, XML knowledge is a must. And after that the question that comes to mind for a Java developer is “How to bind XML data to Java objects”? To make life easy there are frameworks like JAXB, JIBX, Castor, and XMLBeans. So let’s start with JAXB.

  • Java Architecture for XML Binding (JAXB) allows Java developers to map Java classes to XML representations. JAXB provides two main features: the ability to marshal Java objects into XML and the inverse, i.e. to unmarshal XML back into Java objects.
  • JAXB is a part of Java SE platform and one of the APIs in the Java EE platform, and it is part of the Java Web Services Development Pack (JWSDP). It is also one of the foundations for WSIT. For more information refer to the tutorial.
  • Easy to configure when using Maven. When using goal XJC, make sure you provide the required parameters.
  • Now time for some examples. These examples show how to marshall and unmarshall objects.

Overview at a glance:

 Image source: http://java.boot.by/wsd-guide/ch05s03.html

What is with JIBX?

Well the purpose is the same; it is just another tool which is talked about because of its good performance. One can read more about it on their home page.

  • If you have configured your project with Maven, then your goals are quite straight forward. Having said that, it is important to note that the binding tool must be executed before you run your test/main class. It is easy to miss this, since these generated classes will be used at runtime and there are no compile time errors.
  • Though there are no real required parameters to configure but it is good to configure an “outputDirectory” and “schemaBindingDirectory” (see the description here). This will make sure we follow the Maven directory structure.
  • Snippet code to marshall and unmarshall can be found here. Also, when you download the library you can find some examples within the download package.

Both tools require that the XSD file is placed at the correct location as defined in the Maven goals (if you are using an XSD schema file to generate Java code).  With JIBX you can create a WSDL file also.

Next time, when you choose a library you can have a look at the performance and what the industry has to say about it. Here is a compilation of what has been written in an article on IBM. Note that the article is talking about older versions of the libraries.

Image source: http://www.ibm.com/developerworks/xml/library/x-databdopt/

About these ads
  1. 2012-03-07 at 08:36 | #1

    Hi Muqueet,

    The charts you have given are from an article that is dated Jan 1, 2003. In that article it is JAXB 1 (JSR-31) that is being discussed and not JAXB 2 (JSR-222) that is commonly used today.

    -Blaise

  2. Muqeet Khan
    2012-03-08 at 09:11 | #2

    Hi Blaise! I have added a note that the benchmark was done on old libraries. The point is to emphasize that it is important to consider the performance. Thanks for comments.

  1. No trackbacks yet.

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 )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 228 other followers

%d bloggers like this: