• Post Reply Bookmark Topic Watch Topic
  • New Topic

Serialized object size issue  RSS feed

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you measuring the byte size of both values?
 
Sheriff
Posts: 22846
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!