title: Schema Evolution sidebar_position: 8 id: schema_evolution license: | Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Fory supports schema evolution through compatible mode.
let fory = Fory(xlang: true, trackRef: false, compatible: true)
import Fory @ForyObject struct PersonV1 { var name: String = "" var age: Int32 = 0 var address: String = "" } @ForyObject struct PersonV2 { var name: String = "" var age: Int32 = 0 var phone: String? = nil // added field } let writer = Fory(xlang: true, compatible: true) writer.register(PersonV1.self, id: 1) let reader = Fory(xlang: true, compatible: true) reader.register(PersonV2.self, id: 1) let v1 = PersonV1(name: "alice", age: 30, address: "main st") let bytes = try writer.serialize(v1) let v2: PersonV2 = try reader.deserialize(bytes) assert(v2.name == "alice") assert(v2.age == 30) assert(v2.phone == nil)
Int32 to String)With compatible=false, Fory validates schema hash and fails fast on mismatch.