How to Serialize ADB Code Generated Objects

Archived Content
This article is provided for historical perspective only, and may not reflect current conditions. Please refer to relevant product page for more up-to-date product information and resources.
  • By Eran Chinthaka
  • 17 Sep, 2008

We generated code using wsdl2java tool, so that we can see the Web service methods as methods of a Java object. Once generated, we will be using these objects to send and receive parameters to/from the Web service that we are invoking. Take the following method as an example:

public Address getPersonAddress(Person person); 

If this is a method inside your generated stub, you should be able to see Person class and Address class within your source path, as these will also be generated when you code is generated using wsdl2java tool. When you use this generated stub, Axis2 will serialize Person object to XML and send that to the Web service. When Axis2 receives the response, it will populate an Address object from the response XML and pass that back to you. So if you are happy with this approach, you will never have to deal with the underlying SOAP or XML content.

But what if you want to see the underlying XML content of your object? If you generate code using the ADB framework, this is how you can retrieve the XML content. Let's take Address object as an example.

// invoke the Web service
Address address = stub.getPersonAddress(person);

// get the underlying OMElement of Address object
OMElement addressElement = address.getOMElement(Address.MY_QNAME, OMAbstractFactory.getOMFactory());

// serialize the xml element to a string
String addressXMLContent = addressElement.toString();

//print the string
System.out.println("Address Element = " + addressXMLContent); 

Every ADB generated object can generate StAX events from its content. We use our StAX based object model,AXIOM, to get those events and create an XML element. Having got the XML element, it is only a matter of serializing the XML element to a string, in order to retrieve the content.

Applies To


Eran Chinthaka, WS PMC Member/Member-Apache Software Foundation, (FirstName).(LastName)