-1

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?

Zabuzard
  • 25,064
  • 8
  • 58
  • 82
  • 2
    Never ever rely on the output fomat of a serialization if the format is not, per specification, mandated to stay the same. Javas serialization format can (and already has) change between JDK releases. You have to desserialize the file, edit your objects and then re-serialize. – Zabuzard Nov 28 '19 at 18:15
  • 1
    Note also that your question does not show results of your own research efforts in the question, and this may be why you are seeing some down-votes on the question. Please check out the [ask] for best practices when asking questions on this site. – Hovercraft Full Of Eels Nov 28 '19 at 18:20

1 Answers1

1

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.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373