Homemade vs. Java Serialization

前端 未结 14 768
离开以前
离开以前 2021-02-04 06:16

I have a certain POJO which needs to be persisted on a database, current design specifies its field as a single string column, and adding additional fields to the table is not a

14条回答
  •  悲哀的现实
    2021-02-04 06:43

    You need to consider versioning in your solution. Data incompatibility is a problem you will experience with any solution that involves the use of a binary serialization of the Object. How do you load an older row of data into a newer version of the object?

    So, the solutions above which involve serializing to a name/value pairs is the approach you probably want to use.

    One solution is to include a version number as one of field values. As new fields are added, modified or removed then the version can be modified.

    When deserializing the data, you can have different deserialization handlers for each version which can be used to convert data from one version to another.

提交回复
热议问题