alias("customer", Customer.class);
xStream.alias("contact", Contact.class);
Now it is a matter of creating the entity tree, populating its fields, and then calling
the toXML method in XStream. This is reproduced in the following code:
Customer binil = new Customer("Binil", "Das");
binil.setPhone(new Contact(91, "471-2700888"));
String xml = xStream.toXML(binil);
The XML output will look like this:
Binil
Das
91
471-2700888
To reconstruct the object tree back from XML is easy, and is shown as follows:
Customer binilBack = (Customer) xstream.fromXML(xml);
Chapter 12
[ 225 ]
ServiceMix and XStream
ServiceMix has good integration with XStream as a mechanism for XML to Java
binding and vice versa. This is made possible in ServiceMix by exposing a few APIs,
the main ones are listed as follows:
org.apache.servicemix.jbi.messaging.DefaultMarshaler
org.apache.servicemix.components.util.xstream.XStreamMarshaler
org.apache.servicemix.components.util.xstream.XStreamSource
org.
Pages:
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315