aspose file tools
The moose likes Beginning Java and the fly likes Serialized object size issue Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Serialized object size issue" Watch "Serialized object size issue" New topic
Author

Serialized object size issue

joe nesbitt
Greenhorn

Joined: Dec 05, 2009
Posts: 17
Hi all,

I am new to java object serialization.

I have a requirement to compare the byte size of a string aganist the byte size of its serilaized version.

I wrote a small test to understand. I used a empty String and its byte size is zero. But the byte size of the serialized version is 7 bytes.

Q1) How is that possible?

Q2) Also I need to some how make the byte size of seriliazed version match the original String size which is zero? How do I accomplish this?

Any input at the earliest is highly appreciated.

Thanks in advance for your valuable input and time.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 3028
    
    4

How are you measuring the byte size of both values?


Steve
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

joe nesbitt wrote:I wrote a small test to understand. I used a empty String and its byte size is zero. But the byte size of the serialized version is 7 bytes.

Q1) How is that possible?

When you serialize an object, let's say a String, the information which is stored enables anything else to recognize that it is a serialized String. So it's necessary to store information which describes the object as well as storing the contents of the object
Q2) Also I need to some how make the byte size of seriliazed version match the original String size which is zero? How do I accomplish this?
I don't know what "match" means there. If your requirement is that serializing an empty string writes zero bytes, then obviously that's a requirement that can't be implemented.
 
I agree. Here's the link: jrebel
 
subject: Serialized object size issue
 
Similar Threads
applet to servlet
calling all geniuses - major issues :(
Converting Object to String
Convert byte to its hex format?
Byte Operation