XStream Quick Start Albert Guo [email_address]
Agenda <ul><li>Brief Introduction to XStream </li></ul><ul><ul><li>What is XStream </li></ul></ul><ul><ul><li>XStream Feat...
What is XStream <ul><li>XStream is a simple library to serialize objects to XML and back again. </li></ul>© 2006 PTC seria...
XStream Features (1/2) <ul><li>Ease of use </li></ul><ul><ul><li>A high level facade is supplied that simplifies common us...
XStream Features (2/2) <ul><li>Requires no modifications to objects </li></ul><ul><ul><li>Serializes internal fields, incl...
Official Site © 2006 PTC http://xstream.codehaus.org/index.html
Quick Start © 2006 PTC
XStream FAQ © 2006 PTC
Use Case 1: JavaBean To XML serialize objects XML
Use Case 1: JavaBean To XML <ul><li>Prepared two persons’ contact information, including first name, last name phone call ...
Four Steps © 2006 PTC
Step1. Creating classes to be serialized © 2006 PTC
Step2. Preparing data © 2006 PTC
Step3. Initializing XStream © 2006 PTC
Step4. Serializing an object to XML and writing XML object into file © 2006 PTC Source Code
Use Case 2 : XML To JavaBean serialize objects XML
Use Case 2 : XML To JavaBean <ul><li>Read from Person.xml </li></ul><ul><li>Parse the xml file and put contact info into P...
Four Steps © 2006 PTC
Using Alias
Alias <ul><li>Based on the xml file above we shall create some model classes and configure XStream to write/read from this...
Step1. Creating classes to be serialized © 2006 PTC
Step2. Preparing data © 2006 PTC
Step3. Initializing XStream and serializing an object to XML © 2006 PTC
Step3. Initializing XStream and serializing an object to XML © 2006 PTC
Use Alias © 2006 PTC
Using Implicit Collection
Using Implicit Collection <ul><li>Now let's implement what was called an  implicit collection : whenever you have a collec...
The Model © 2006 PTC
Simple Test © 2006 PTC
Simple Test © 2006 PTC
Simple Test © 2006 PTC
Result © 2006 PTC
Upcoming SlideShare
Loading in …5
×

XStream Quick Start

1,832
-1

Published on

Published in: Technology, Travel
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,832
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
29
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

XStream Quick Start

  1. 1. XStream Quick Start Albert Guo [email_address]
  2. 2. Agenda <ul><li>Brief Introduction to XStream </li></ul><ul><ul><li>What is XStream </li></ul></ul><ul><ul><li>XStream Features </li></ul></ul><ul><ul><li>Official Site </li></ul></ul><ul><ul><li>FAQ </li></ul></ul><ul><li>Use Cases </li></ul><ul><ul><li>Use Case 1: JavaBean To XML </li></ul></ul><ul><ul><li>Use Case 2 : XML To JavaBean </li></ul></ul><ul><li>Using Alias </li></ul><ul><li>Using Implicit Collection </li></ul>© 2006 PTC
  3. 3. What is XStream <ul><li>XStream is a simple library to serialize objects to XML and back again. </li></ul>© 2006 PTC serialize objects XML
  4. 4. XStream Features (1/2) <ul><li>Ease of use </li></ul><ul><ul><li>A high level facade is supplied that simplifies common use cases. </li></ul></ul><ul><li>No mappings required </li></ul><ul><ul><li>Most objects can be serialized without need for specifying mappings. </li></ul></ul><ul><li>Performance </li></ul><ul><ul><li>Speed and low memory footprint are a crucial part of the design, making it suitable for large object graphs or systems with high message throughput. </li></ul></ul><ul><li>Clean XML </li></ul><ul><ul><li>No information is duplicated that can be obtained via reflection. This results in XML that is easier to read for humans and more compact than native Java serialization. </li></ul></ul><ul><li>. </li></ul>© 2006 PTC
  5. 5. XStream Features (2/2) <ul><li>Requires no modifications to objects </li></ul><ul><ul><li>Serializes internal fields, including private and final. Supports non-public and inner classes. Classes are not required to have default constructor. </li></ul></ul><ul><li>Full object graph support </li></ul><ul><ul><li>Duplicate references encountered in the object-model will be maintained. Supports circular references. </li></ul></ul><ul><li>Integrates with other XML APIs </li></ul><ul><ul><li>By implementing an interface, XStream can serialize directly to/from any tree structure (not just XML). </li></ul></ul><ul><li>Customizable conversion strategies </li></ul><ul><ul><li>Strategies can be registered allowing customization of how particular types are represented as XML. </li></ul></ul><ul><li>Error messages </li></ul><ul><ul><li>When an exception occurs due to malformed XML, detailed diagnostics are provided to help isolate and fix the problem </li></ul></ul>© 2006 PTC
  6. 6. Official Site © 2006 PTC http://xstream.codehaus.org/index.html
  7. 7. Quick Start © 2006 PTC
  8. 8. XStream FAQ © 2006 PTC
  9. 9. Use Case 1: JavaBean To XML serialize objects XML
  10. 10. Use Case 1: JavaBean To XML <ul><li>Prepared two persons’ contact information, including first name, last name phone call and fax number </li></ul><ul><li>System should write these contact information into Person.xml correctly </li></ul>© 2006 PTC serialize objects XML
  11. 11. Four Steps © 2006 PTC
  12. 12. Step1. Creating classes to be serialized © 2006 PTC
  13. 13. Step2. Preparing data © 2006 PTC
  14. 14. Step3. Initializing XStream © 2006 PTC
  15. 15. Step4. Serializing an object to XML and writing XML object into file © 2006 PTC Source Code
  16. 16. Use Case 2 : XML To JavaBean serialize objects XML
  17. 17. Use Case 2 : XML To JavaBean <ul><li>Read from Person.xml </li></ul><ul><li>Parse the xml file and put contact info into Person bean </li></ul>© 2006 PTC XML To JavaBean serialize objects XML
  18. 18. Four Steps © 2006 PTC
  19. 19. Using Alias
  20. 20. Alias <ul><li>Based on the xml file above we shall create some model classes and configure XStream to write/read from this format. </li></ul>© 2006 PTC
  21. 21. Step1. Creating classes to be serialized © 2006 PTC
  22. 22. Step2. Preparing data © 2006 PTC
  23. 23. Step3. Initializing XStream and serializing an object to XML © 2006 PTC
  24. 24. Step3. Initializing XStream and serializing an object to XML © 2006 PTC
  25. 25. Use Alias © 2006 PTC
  26. 26. Using Implicit Collection
  27. 27. Using Implicit Collection <ul><li>Now let's implement what was called an implicit collection : whenever you have a collection which doesn't need to display it's root tag, you can map it as an implicit collection. </li></ul><ul><li>In our example, we do not want to display the orderList tag, but simply show the Order tags one after another. </li></ul><ul><li>A simple call to the addImplicitCollection method shall configure XStream and let it know that we do not want to write the orderList tag as described above: </li></ul>© 2006 PTC
  28. 28. The Model © 2006 PTC
  29. 29. Simple Test © 2006 PTC
  30. 30. Simple Test © 2006 PTC
  31. 31. Simple Test © 2006 PTC
  32. 32. Result © 2006 PTC
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×