Managing several versions of serialized Java objects

前端 未结 4 774
野趣味
野趣味 2020-11-30 05:44

Lets say that I have a program that for some reason need to handle old versions of serialized objects.

Eg: when deserializing, one of these versions may be encounter

4条回答
  •  误落风尘
    2020-11-30 06:03

    Should I do deserialization in one class loader, and if that fails try using another class loader that uses an older version (and so on), or are there better ways?

    What's the best strategy?

    Serialization really shouldn't be used for long term storage.

    The best strategy here is to make use of a database instead: store your objects in a Pets table, then as you change fields on your table, all of your old data gets updated too, every object has the same and most up-to-date schema.

    This is really the best way to maintain data for longterm storage, and updates to your old objects to fill in null fields is really easy.

提交回复
热议问题