fix empty object emitted for optional property with only null values#540
Merged
Conversation
FeatureTokenTransformerRemoveEmptyOptionals defers an optional object and
opens it lazily when a sub-property has to be emitted. It kept null values of
any property marked required, so a required-but-null sub-property forced its
optional wrapper open — emitted as an empty object ({} in GeoJSON, an empty
element in GML) instead of being omitted.
onValue/onGeometry now treat a property as required only if it and every
wrapping property up to the feature are required, reusing the rule the context
already exposes via isRequired(schema, parentSchemas). A required sub-property
inside an optional object is therefore not effectively required: when all of
the object's values are null the wrapper is dropped, while a wrapper that still
carries non-null content drops only its null required siblings.
The change is at the token level, so both the GeoJSON and GML encoders benefit.
Adds spec coverage for the all-null and partial cases.
azahnen
approved these changes
Jun 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
FeatureTokenTransformerRemoveEmptyOptionals defers an optional object and opens it lazily when a sub-property has to be emitted. It kept null values of any property marked required, so a required-but-null sub-property forced its optional wrapper open — emitted as an empty object ({} in GeoJSON, an empty element in GML) instead of being omitted.
onValue/onGeometry now treat a property as required only if it and every wrapping property up to the feature are required, reusing the rule the context already exposes via isRequired(schema, parentSchemas). A required sub-property inside an optional object is therefore not effectively required: when all of the object's values are null the wrapper is dropped, while a wrapper that still carries non-null content drops only its null required siblings.
The change is at the token level, so both the GeoJSON and GML encoders benefit. Adds spec coverage for the all-null and partial cases.