If you are using restful web services (I'd recommend Jersey if you are http://jersey.dev.java.net) you can pass JAXB annotated objects. Jersey will automatically serialize and deserialize your objects on both the client and server side.
Server side;
@Path("/mypath")
public class MyResource
{
@GET
@Produces(MediaType.APPLICATION_XML)
public MyBean getBean()
{
MyBean bean = new MyBean();
bean.setName("Hello");
bean.setMessage("World");
return bean;
}
@POST
@Consumers(MediaType.APPLICATION_XML)
public void updateBean(MyBean bean)
{
//Do something with your bean here
}
}
Client side;
//Get data from the server
Client client = Client.create();
WebResource resource = client.resource(url);
MyBean bean = resource.get(MyBean.class);
//Post data to the server
bean.setName("Greetings");
bean.setMessage("Universe");
resource.type(MediaType.APPLICATION_XML).post(bean);
JAXB bean;
@XmlRootElement
public class MyBean
{
private String name;
private String message;
//Constructors and getters/setters here
}