wood burning stoves 2.0*
The moose likes Web Services and the fly likes Difference between (Java to XML) binding and serialization, JAXB and XStream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Web Services
Bookmark "Difference between (Java to XML) binding and serialization, JAXB and XStream" Watch "Difference between (Java to XML) binding and serialization, JAXB and XStream" New topic
Author

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

Ganesh Kandisa
Greenhorn

Joined: Jul 27, 2011
Posts: 6

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%)


Ganesh Kandisa
OCPJP 6(93%),OCPWCD 5(92%)
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
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.


My free books and tutorials: http://www.slideshare.net/krizsan
Ganesh Kandisa
Greenhorn

Joined: Jul 27, 2011
Posts: 6

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

Joined: Oct 04, 2006
Posts: 2198
    
    1
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!
 
GeeCON Prague 2014
 
subject: Difference between (Java to XML) binding and serialization, JAXB and XStream