• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Difference between (Java to XML) binding and serialization, JAXB and XStream

 
Greenhorn
Posts: 6
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys..

In our work we are using XStream to marshal/unmarshall for RESTful resources.Here XStream exactly behaves like JAXB except different annotatons. They say XStream is aserialization frame and should not be confused with JAXB which is binding frame work.

Does anyone clarify the differnece between these two please..

Thank you,

Ganesh Kandisa
------------------
OCPJP 6(93%),OCPWCD 5(92%)
 
Ranch Hand
Posts: 2198
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
Serialization, to me, is when you from an object create a data representation of that object that, for instance, can be transferred using some means of communication.
With serialization, the object is the "mould" to create the serialized data from - the object is introspected and the data it contains is extracted.
If the class of the object changes, it still can be serialized without having to change any code or re-generating anything.
The serial representations before and after the change may not be compatible, but that is another issue.

With JAXB, an XML schema is the "mould" that specifies how the representation of an object is to look like.
From the XML schema, one or more JAXB bean classes are created. These JAXB bean classes are the Java representation of the data structure specified by the XML schema.
The JAXB framework then can transfer from XML data to an object structure that consists of instances of JAXB bean classes or vice versa.
If the XML schema changes, you typically have to re-generate the JAXB bean classes.

I think the basic difference is: What is first?
With serialization, it is an object. With JAXB, it is an XML schema.
Hope this makes sense.
 
Ganesh Kandisa
Greenhorn
Posts: 6
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ivan for your reply..

But without any XML Schema, i can annotate my simple POJO with JAXB annotations and using JAXB context i can marshal this object to XML representation which is exactly we are doing in XStream also. so if JAXB is only the binding framework does it mean that it wont take burden of serialization process instead it simply maps the xml nodes to bean properties?, i mean underlying JAX-WS will take care of this serialization while in the SOAP response?

Please correct if i am wrong..


Ganesh Kandisa
--------------------------
OCPJP(93%),OCPWCD(92%)
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
I must admit that I am not familiar with XStream.
JAXB is the framework responsible for transforming XML to a Java object structure and vice versa when using JAX-WS.
JAX-RPC has a serialization mechanism built in to the framework, but with JAX-WS this was extracted to a framework that can be used independent of JAX-WS.
JAXB uses the metadata (annotations) in the JAXB bean classes in order to know in which field to put what part of the XML data and the other way around.

Perhaps there is not that much of a difference between XStream and JAXB apart from words used when talking about one or the other...
Best wishes!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic