Skip to Content

Forget SAX and DOM. JAVA mapping just got cooler with JAXB! (Part 1)

Traditionally when PI consultants are asked about Java mapping, SAX and DOM parsers would be the first to cross their minds. But this blog is here to change that view.

After the blog XML / XSD Validation – An Alternative for SAP PI, I happened to receive queries around JAXB and its usage. Since JAXB is a XML binding framework, one of the best use cases it has in the world of integration is around XML mapping.

In this blog we will look at how to use JAXB and thus develop a Java mapping without the use of a SAX or DOM parser.

Below is a quick reference to JAXB, as it will not be in the scope of this blog to explain JAXB in detail;

1) Java Architecture for XML Binding (JAXB) –

2) Marshal and Unmarshal in JAXB –

Setting up the Environment:

1) Source XSD

Below is the schema that we will use for the source message;

2) Target XSD

Below is the graphical schema representation of the target message;

3. Create a java project in NWDS. Create two folders, sourceData and targetData with packages sourceData and targetData respectively.

4. Import the source XSD into the sourceData folder and the Target XSD into the targetData folder.

5. Using XJC to create the required java classes related to the source and target XSD

There are two ways you can use XJC to build the Java classes for your XSDs.

a. Use the command line, XJC <XSD File name> . If you want to have a control on the package name created for these classes use, XJC –p <package name> <XSD File name>

Once the files are generated, import them into their respective folders i.e sourceData or targetData

b. External tool in NWDS – Configure the XJC bat file as an external tool in NWDS and use it to generate the classes directly in NWDS itself.

Your NWDS should look something as below;


In the next part, we will look at how to code and use JAXB to our advantage.

You must be Logged on to comment or reply to a post.
  • Instead of using the xjc for generation, you can use the SAP graphical wizards. 

    In ESR perspective, click the service interface

    Generate Client

    follow the wizard to generate the artifacts.

    sometimes it is necessary to mess with the classloader, otherwise the marshalling unmarshalling won’t work or it is impossinle to create jaxb context


    ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
      try {
    // JAXB coding and mapping

    String contextPath = ItemType.class.getPackage().getName();

    JAXBContext jc = JAXBContext.newInstance(contextPath);

    // more coding

      } finally {

    using the wizard avoids using jaxb customizing which can be tricky

    • Hi Otto,

      I am able to generate class for source but when I am trying to create target in same project I am getting error “SAP NetWeaver Web Service runtime does not support client project ProjectName”. Is there any link/blog that guides through this approach to generate classes for both source and target in same project?