Why are you concerned about gaps in ObjectOutputStream. Its mainly used for writing to file and recreating objects back. If you want to use it to write it to a file in a human readable format suggest you to use normal file output stream and not object output stream.