Programming · free software · the open webSubscribe via RSS

How Can a Schema Handle Future Fields?

From the earlier reference collection. Read the current software blog.

A schema should tell clients how to behave when new fields appear, so evolution does not turn ordinary additions into failures.

Decide how unknown fields behave

A client may encounter a field that did not exist when it was written. The schema should say whether clients are expected to ignore unknown fields, preserve them, or reject the document. For many data APIs, ignoring unknown optional fields makes it possible to add information without requiring every client to update at once.

Strict rejection can still be appropriate when accepting an unrecognized field could cause a safety or correctness problem. The choice depends on the interface and the consequence of misinterpretation. Make the policy explicit so client authors do not guess from one example implementation.

Separate optionality from meaning

An optional field can be absent, but clients still need to know what absence means. It might mean the value was not collected, the feature is not relevant, or the producer does not support the field. If these cases matter, use a defined status or capability rather than treating omission as a universal explanation.

When adding a field, choose a name and meaning that do not change existing fields. For example, adding a display label can complement a stable identifier; it should not quietly redefine the identifier as a user-facing name. Additions are easiest to absorb when old data retains its original interpretation.

Preserve data where needed

Some clients decode a document into a fixed object and discard anything they do not recognize. That can be acceptable for a display-only client but harmful for a proxy that reads and forwards the data. A forwarding client may need to preserve unknown fields so information survives an intermediate system.

Document which role applies to each interface or client type. If preservation is required, test that an unknown field passes through a read-and-write cycle unchanged. If clients may ignore the field, ensure the core task remains correct without it.

Plan and test evolution

Before release, add a sample containing an unknown field and check how representative clients behave. Also test omitted optional fields and null values separately; they are not automatically equivalent. A schema change should explain whether the field is optional, who may send it, and how clients can safely use it.

Forward compatibility is a contract between producers and consumers. Clear unknown-field rules, stable existing meanings, and tests against realistic clients let a schema grow gradually. The practical test is whether an older client can continue its intended task when a newer producer adds information.

Suggest a correction · All posts