When adding new properties to serialization methods, use `WritePropertyWithDefault` and `ReadPropertyWithDefault` instead of `WriteProperty` and `ReadProperty` to maintain backwards compatibility. This ensures that older versions can still deserialize data written by newer versions by providing sensible defaults for missing properties.
When adding new properties to serialization methods, use WritePropertyWithDefault
and ReadPropertyWithDefault
instead of WriteProperty
and ReadProperty
to maintain backwards compatibility. This ensures that older versions can still deserialize data written by newer versions by providing sensible defaults for missing properties.
Without default methods, adding new serialized properties breaks backwards compatibility because older versions cannot handle the new data format. Using default methods allows graceful degradation where older versions use default values for properties they don’t understand.
Example:
// Bad - breaks backwards compatibility
serializer.WriteProperty(212, "extra_info", extra_info);
// Good - maintains backwards compatibility
serializer.WritePropertyWithDefault(212, "extra_info", extra_info);
Additionally, be cautious with ShouldSerialize()
checks that might cause information loss when serializing to older storage versions. If critical data would be lost, prefer throwing an error on deserialization rather than silently dropping information.
Enter the URL of a public GitHub repository