Serialization
The document model, the serializer seam, and why documents are shaped like JSON but trusted only after verification.
Two layers, deliberately separate#
| Layer | What it is | Replaceable |
|---|---|---|
| Document model | A neutral tree (DataNode) that holds your values with no knowledge of your types | It is the framework's contract; you work with it, not around it |
| Serializer | Turns the document tree into bytes and back | Yes — NexusForge.Persistence.Serializers.Newtonsoft is the shipped one, and the seam is public |
var document = new DataNodeObject(); // what a capture produces
byte[] payload = serializer.Serialize(document);Because the document is neutral, the framework can migrate, verify, compress and encrypt it without ever knowing who a "player" is.
What the shipped serializer is#
JSON, via com.unity.nuget.newtonsoft-json — the package's single runtime dependency, resolved by the Package Manager. Documents are JSON-shaped, and they are trusted only after integrity verification, never before.
Unknown members survive#
When a newer build writes a member an older build does not know, the older build preserves it rather than dropping it, so a downgrade or a rollback does not wipe data. That costs some size on documents that change schema often, and it is a deliberate trade: silent data loss is worse than a slightly larger file. The policy is configurable — see Unknown data.
Replacing the serializer#
Implement the serializer seam and compose the service with yours. Two things to keep in mind:
- A custom serializer must still produce a deterministic, culture-independent representation of values that have a text form (dates, decimals). This is exactly where an early culture bug came from — see Supported types.
- Migration operates on the document, not on bytes, so a custom serializer does not affect migration.
Next#
- Save format — the container around the payload.
- Unknown data — the three policies, and which is the default.
- Extending NexusForge — the seam in practice.
Something wrong on this page? Every page here describes behaviour that is checked in the repository. If a page and the package disagree, the package wins.
Report a documentation problem · Frequently asked questions · Troubleshooting