Schema Evolution
Apache Fory™ supports schema evolution in Compatible mode, allowing fields to be added/removed while maintaining compatibility.
Enable Compatible Mode
import pyfory
f = pyfory.Fory(xlang=True, compatible=True)
Schema Evolution Example
import pyfory
from dataclasses import dataclass
# Version 1: Original class
@dataclass
class User:
name: str
age: int
f = pyfory.Fory(xlang=True, compatible=True)
f.register(User, typename="User")
data = f.dumps(User("Alice", 30))
# Version 2: Add new field (backward compatible)
@dataclass
class User:
name: str
age: int
email: str = "[email protected]" # New field with default
# Can still deserialize old data
user = f.loads(data)
print(user.email) # "[email protected]"
Supported Changes
- Add new fields: With default values
- Remove fields: Old data with extra fields will be skipped
- Reorder fields: Fields are matched by name, not position
Best Practices
- Always provide default values for new fields
- Use typename for cross-language compatibility
- Test schema changes before deploying
- Document schema versions for your team
Related Topics
- Configuration - Compatible mode settings
- Cross-Language - Schema evolution across languages
- Type Registration - Registration patterns