jQuery in Action, 3rd edition
The moose likes Distributed Java and the fly likes JSON serialization. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "JSON serialization." Watch "JSON serialization." New topic

JSON serialization.

Claude Moore
Ranch Hand

Joined: Jun 24, 2005
Posts: 720

Hi there,

I have a couple of questions about JSON serialization of Java objects.

a) I wonder if JSON serialization may or not be a valid replacement for Java standard serialization even when used in a very general way, I mean: even when one's going to
serialize and deserialize an arbitrary complex object, and you can't or you don't won't to use special annotations on class you're going to serialize/deserialize.

b) Would be - generally speaking - JSOn serialization faster and/or a better performer than Java default serialization with respect to bandwidth usage ?

c) If you needed maxim control over JSon serialization mechanism, which library would you suggest to use ?

Thank you.

Luan Cestari
Ranch Hand

Joined: Feb 07, 2010
Posts: 163

a) You might get some problem with Generic Types. There are other problems (some I will mention answering the next questions but others I don't remember right now) I didn't understood the second part of this question about the annotations and other things.

b) Java serialization will turn the content into binary and compress it using zip. So it is much smaller (the bigger the object, the bigger would be the different size of the JSON and Java serialization). About which one is faster, I would say if you consider both in memory, probably the time is almost the same, maybe a bit more time in the Java serialization due the compression algorithm but maybe not due the necessary processing for JSON serialization. Also if you consider to persit it or to send over the entwork, the Java serialization would be faster.

c) I would say jackson

Please, visit me for some cool tech post at www.ourdailycodes.com
Claude Moore
Ranch Hand

Joined: Jun 24, 2005
Posts: 720


first, thanks really for your answer.

About question a), I try and be clearer... With Java serialization, you have an out-of-the-box mechanism to marshal any kind of object, no matter how complex it may be. I've seen that under certain circumstances
you may need to use specific JSON-library annotations to take control over "serialization" mechanism.. I have in mind,for example, just Jackson library you suggest me as a viable option.

About data size after serialization, well, compression is not specific or built in with Java serialization... you may compress Jackson data as well, so the problem would be: which type of serialization as
the minimal representation payload ? XML is known to be very verbose; JSON is by far more concise than XML.... I'd like to have a general framework for serialization where information about typing (for example)
isn't lost.

I agree. Here's the link: http://aspose.com/file-tools
subject: JSON serialization.
It's not a secret anymore!