@@ -202,6 +202,28 @@ public module FieldSerializableLifecycle
202202 deserialize(input)
203203 return this
204204
205+ /**
206+ Automatic field mapping without adding a second `serialize`/`deserialize` lifecycle.
207+
208+ Use this during a compatibility window when a data class still extends legacy `Serializable`, or
209+ when another base class already owns lifecycle methods. The class must implement `FieldSerializable`.
210+ All of its accessible mutable instance fields participate; keep runtime-only state in a separate
211+ class because persisted-field annotation filtering is not available.
212+ */
213+ public module SerializableFieldMapping
214+ function writeSerializedFields(FieldSerializationWriter writer)
215+ wurstForFields((fieldName, value) -> writer.write(fieldName, value))
216+
217+ function readSerializedFields(FieldSerializationReader reader)
218+ wurstMapFields((fieldName, value) -> value.readSerializedField(reader, fieldName))
219+
220+ function readSerializedField(FieldSerializationReader reader, string name) returns thistype
221+ let child = reader.readObject(name)
222+ if child.isValid()
223+ readSerializedFields(child)
224+ destroy child
225+ return this
226+
205227/**
206228Modern automatic serialization for dedicated state/DAO classes using built-in codecs.
207229
@@ -210,7 +232,8 @@ iteration to direct accesses. The tagged format tolerates field reordering, adde
210232and unknown future wire types. Missing fields retain constructor defaults. Use a schema version and
211233`SerializationMigration` for semantic changes or `renameField` for renamed attributes. For custom
212234tuple codecs declared in the consuming package, use `FieldSerializableLifecycle` as documented
213- above so overload resolution occurs where those codecs are visible.
235+ above so overload resolution occurs where those codecs are visible. Classes that must also retain
236+ legacy `Serializable` should use `SerializableFieldMapping` to avoid conflicting lifecycle methods.
214237*/
215238public module SerializableFields
216239 use FieldSerializableLifecycle
0 commit comments