I am wondering what serialized mechanism should we choose when dealing with object transferring over the network. What are the pros and cons ?
I know most of the tim
While serialization over the network both XML and JSON would work. It depends on the consumer of this information.
If the consumer is a browser using Ajax to request some information and render something on the screen, generally JSON is the best bet as its already in Javascript object format and there is no overhead of converting to Javascript compatible objects. In fact many Ajax libs (e.g. jQuery) have good support for JSON.
If you consumer is another application which may or may not be in java, then XML is the prefer serialization mechanism. Web services use XML very heavily.
If your consumer is another Java program then definitely java serialization is preferred option (e.g. RMI). So its not out yet :-).
But yes there is blurred line between XML and JSON. What I mentioned here is the general practice. Here is a nice article putting all the aspect on XML vs JSON.