, , , , , ,

Some days back, when I wanted to write a web service using Axis, I encountered a problem in passing objects to and returning objects from the methods exposed by the web service. I wanted to just write a jws and invoke it directly without worrying about the deployment processes of the web services like WSDL2Java, deploy.wsdd etc. This approach worked fine when I had to deal only with primitive parameters and return values.

But when I wanted to pass a user defined object, Axis threw exceptions because it could not serialize the object in order to transmit it as an XML. The solutions I found required me to know a few inner details about the web service that are available in deploy.wsdd, the web service deployment descriptor. Since I could not afford to spend further time in exploring web services, I have chosen not to follow this round-about way, at least for now.

Now, the alternative is to pass and return objects as XML and the question is how to convert an XML to a Java object and vice versa ? A little bit of googling made me realise that this is a very standard problem and there are loads of libraries for doing the same. But the simplest of the solutions for the XML-object binding problem seems to be using the XMLEncoder & XMLDecoder classes. They are simple and work good enough for me !