Skip to content

fix(schema): replace state during JSON decoding - #1628

Open
fallintoplace wants to merge 2 commits into
apache:mainfrom
fallintoplace:fix/schema-unmarshal-replace-state
Open

fix(schema): replace state during JSON decoding#1628
fallintoplace wants to merge 2 commits into
apache:mainfrom
fallintoplace:fix/schema-unmarshal-replace-state

Conversation

@fallintoplace

@fallintoplace fallintoplace commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

What changed

Make Schema.UnmarshalJSON decode and validate into fresh temporary state, then replace the receiver only after the complete document is valid. On success, clear every cached lookup index and rebuild the lazy parent and name-mapping functions for the new schema.

Why

The decoder previously unmarshaled through the existing receiver. Reusing a Schema could therefore retain values omitted from the next document, including schema-id and identifier-field-ids. Cached lookups could continue returning fields from the previous schema.

Duplicate-field validation also ran after the receiver had already been modified, so invalid input could leave a partially updated schema behind. Decoding transactionally gives successful reuse replacement semantics while preserving the original value on error.

Testing

  • reused receiver clears omitted schema metadata
  • ID, name, case-insensitive name, and name-mapping caches reflect the replacement schema
  • invalid duplicate IDs preserve the original schema
  • go test .
  • go vet .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant