This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSON serialization.

 
Claude Moore
Ranch Hand
Posts: 746
7
IBM DB2 Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 163
C++ Redhat Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Claude Moore
Ranch Hand
Posts: 746
7
IBM DB2 Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Luan,

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.




 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic