javafileserializationdeserializationobjectoutputstream

Editing serialized object


I have a serialized object stored in a file (with ObjectOutputStream).

Is it possible to edit the serialized object in the file without deserializing and re-writing the file?


Solution

  • No, you can't and shouldn't edit the file directly. You need to de-serialize the data, change it, and then re-serialize it. Doing anything else would be dangerous. Many in fact advise folks not to serialize data using Java serialization library but rather serialize to a readable format such as XML or JSON, or store data in a database, a much more flexible and powerful construct, instead.