title: How can I read the size in bytes of a serialized object in Java?
body: <p>Is there a way of reading the total used size of a serialized object from stream before or after deserializing it?</p>
  
  <p>The only way I could find was to serialize it again into a byte buffer and see that buffer total occupied size. This works, but it seems to be a waste of resources.</p>
  
  <p>Edit: I'm not interested in the space that the Object instance uses while loaded in memory. Only the serialized size in bytes.</p>