The main features of XStream are listed as follows:
Ease for use: A high-level facade-class called XStream is supplied which
simplifies the common use cases.
No mappings required: Most objects can be serialized by registering
their class.
Performance: XStream is suitable for large object graphs or systems with
high message throughput.
Works on normal objects: Serializes internal fields, including private and
final. Supports non-public and inner classes. The classes are not required to
have a default constructor.
Full object graph support: Duplicate references encountered in the
object-model will be maintained. Supports circular references.
Integrates with other XML APIs: By implementing suitable interfaces,
XStream supports serialization directly to or from any tree structure
including XML.
??? ??? ??? ??? ??? ??? ??? ??? ???
Java XML Binding Using XStream
[ 224 ]
Let us also look at a sample binding using XStream. Consider the following two
classes namely the Customer and the Contact:
public class Customer
{
private String firstName;
private String lastName;
private Contact phone;
}
public class Contact
{
private int code;
private String number;
}
Now, if you have to use XStream to convert the above entities to XML, then first
instantiate the XStream fa?§ade and create aliases for your custom class names to
XML element names as shown in the following code:
XStream xStream = new XStream();
xStream.
Pages:
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314