Skip to content

Simplify JSON de/serialization in TypeScript - #680

Merged
mristin merged 1 commit into
mainfrom
mristin/Simplify-typescript-jsonization-and-xmlization
Sep 6, 2026
Merged

mristin merged 1 commit into
mainfrom
mristin/Simplify-typescript-jsonization-and-xmlization

Conversation

@mristin

@mristin mristin commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

We add generic parseArray/serializeArray helpers for JSON list (de)serialization, replacing per-property inlined boilerplate with shared calls.

Call sites pass a bare function reference wherever the existing per-type function already has the right signature, and reach for a lambda only where this must be captured. Concretely, serializeArray is called with AasCommon.base64Encode for byte-array items and with AasStringification.must{Enum}ToString for enumeration items, while class items still need (item) => this.transform(item). Lists of identity primitives (bool/int/float/str) skip serializeArray altogether and use Array.from for a defensive copy, since no per-item transformation is needed.

TypeScript's XML (de)serialization is left untouched: XML deserialization was already simplified in a separate, earlier pull request (#671).

We add generic ``parseArray``/``serializeArray`` helpers for JSON
list (de)serialization, replacing per-property inlined boilerplate
with shared calls.

Call sites pass a bare function reference wherever the existing
per-type function already has the right signature, and reach for a
lambda only where ``this`` must be captured. Concretely,
``serializeArray`` is called with ``AasCommon.base64Encode`` for
byte-array items and with ``AasStringification.must{Enum}ToString``
for enumeration items, while class items still need
``(item) => this.transform(item)``. Lists of identity primitives
(``bool``/``int``/``float``/``str``) skip ``serializeArray``
altogether and use ``Array.from`` for a defensive copy, since no
per-item transformation is needed.

TypeScript's XML (de)serialization is left untouched: XML
deserialization was already simplified in a separate, earlier pull
request (#671).
@mristin
mristin merged commit d0d1f17 into main Sep 6, 2026
3 checks passed
@mristin
mristin deleted the mristin/Simplify-typescript-jsonization-and-xmlization branch September 6, 2026 07:49
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