Skip to content

Simplify JSON, XML de/serialization in TypeScript - #681

Merged
mristin merged 1 commit into
eclipse-aascw:mainfrom
mristin:mristin/Simplify-JSON-and-XML-serialization
Sep 9, 2026
Merged

mristin merged 1 commit into
eclipse-aascw:mainfrom
mristin:mristin/Simplify-JSON-and-XML-serialization

Conversation

@mristin

@mristin mristin commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

We factor out repeated boilerplate in the generated TypeScript de/serialization code into shared runtime helpers, reducing generated code size and fixing a couple of genuinely redundant computations.

JSON parsing:

  • checkIsIterable(jsonable) replaces the null/typeof/Symbol.iterator checks that were duplicated at every list-typed property setter.
  • checkIsJsonObject(jsonable) replaces the null/Array.isArray/typeof checks duplicated at every concrete class's and interface's fromJsonable function.
  • checkModelType(modelType, expected) replaces the required/mismatch check duplicated once per class with a model type.

XML serialization:

  • writeVElement/writeClassElement push directly into the shared parts array instead of each call site inlining openTag/content/closeTag, without introducing any extra string concatenation or array allocation compared to the original code.

XML parsing:

  • nextPropertyOpenTag(cursor, className) replaces the ~25-line token-read/end-of-stream/close-tag/wrong-token-kind/namespace-check preamble that was duplicated in every class's property-parsing loop. It returns the token, null, or a DeserializationError directly, so it adds no allocation over the original inlined code despite running once per property parsed, not just once per instance.
  • Property close-tag consumption now reuses the already-computed propertyLocalName instead of redundantly recomputing localNameOfTag(propertyStartTag.tag).

We factor out repeated boilerplate in the generated TypeScript
de/serialization code into shared runtime helpers, reducing generated
code size and fixing a couple of genuinely redundant computations.

JSON parsing:
* checkIsIterable(jsonable) replaces the null/typeof/Symbol.iterator
  checks that were duplicated at every list-typed property setter.
* checkIsJsonObject(jsonable) replaces the null/Array.isArray/typeof
  checks duplicated at every concrete class's and interface's
  fromJsonable function.
* checkModelType(modelType, expected) replaces the required/mismatch
  check duplicated once per class with a model type.

XML serialization:
* writeVElement/writeClassElement push directly into the shared
  `parts` array instead of each call site inlining
  openTag/content/closeTag, without introducing any extra string
  concatenation or array allocation compared to the original code.

XML parsing:
* nextPropertyOpenTag(cursor, className) replaces the ~25-line
  token-read/end-of-stream/close-tag/wrong-token-kind/namespace-check
  preamble that was duplicated in every class's property-parsing
  loop. It returns the token, `null`, or
  a DeserializationError directly, so it adds no allocation over
  the original inlined code despite running once per
  property parsed, not just once per instance.
* Property close-tag consumption now reuses the already-computed
  `propertyLocalName` instead of redundantly recomputing
  `localNameOfTag(propertyStartTag.tag)`.
@mristin
mristin merged commit 5ef8054 into eclipse-aascw:main Sep 9, 2026
5 checks passed
@mristin
mristin deleted the mristin/Simplify-JSON-and-XML-serialization branch September 9, 2026 18:11
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