From b7126518dd0ac92e592cad66e88e3d8f6611d22f Mon Sep 17 00:00:00 2001 From: Josh Wulf Date: Mon, 29 Jul 2024 20:30:22 +1200 Subject: [PATCH 1/2] fix(lossless-parser): correctly handle null in objects the lossless parser now correctly handles null fields in objects fixes #212 --- .vscode/settings.json | 3 ++- src/__tests__/lib/LosslessJsonParser.unit.spec.ts | 14 ++++++++++++++ src/lib/LosslessJsonParser.ts | 5 ++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 0561ac70..9df51550 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,7 +8,8 @@ "modeler", "operate", "camunda8", - "optimize" + "optimize", + "lossless-parser" ], "editor.formatOnSave": true, diff --git a/src/__tests__/lib/LosslessJsonParser.unit.spec.ts b/src/__tests__/lib/LosslessJsonParser.unit.spec.ts index 6e04fc2a..26d22244 100644 --- a/src/__tests__/lib/LosslessJsonParser.unit.spec.ts +++ b/src/__tests__/lib/LosslessJsonParser.unit.spec.ts @@ -330,3 +330,17 @@ test('LosslessStringify correctly handles nested Dtos', () => { `{"total":3,"decisionsOutputs":[{"someInt32Field":123,"someInt64Field":123}]}` ) }) + +test('LosslessJsonParser correctly handles null objects', () => { + const json = `{"abc": [null, null, null] }` + + const parsedDto = losslessParse(json) + expect(parsedDto.abc).toMatchObject([null, null, null]) // 3 (string) +}) + +test('LosslessStringify correctly handles null objects', () => { + const json = { abc: [null, null, null] } + + const stringifiedDto = losslessStringify(json) + expect(stringifiedDto).toBe(`{"abc":[null,null,null]}`) // 3 (string) +}) diff --git a/src/lib/LosslessJsonParser.ts b/src/lib/LosslessJsonParser.ts index 637f090b..8c62a54d 100644 --- a/src/lib/LosslessJsonParser.ts +++ b/src/lib/LosslessJsonParser.ts @@ -220,7 +220,10 @@ function parseArrayWithAnnotations( * Convert all `LosslessNumber` instances to a number or throw if any are unsafe */ function convertLosslessNumbersToNumberOrThrow(obj: any): T { - debug(`Parsing LosslessNumbers to numbers for ${obj.constructor.name}`) + debug(`Parsing LosslessNumbers to numbers for ${obj?.constructor?.name}`) + if (!obj) { + return obj + } let currentKey = '' try { Object.keys(obj).forEach((key) => { From 3c72a5812ef1bf6f2781301a38bd4faad5c27ded Mon Sep 17 00:00:00 2001 From: Josh Wulf Date: Tue, 30 Jul 2024 06:21:38 +1200 Subject: [PATCH 2/2] chore(repo): fix license field the license field is now Apache-2.0 allowing for correct parsing by tools --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4c818e7d..df204ecf 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "access": "public" }, "author": "josh.wulf@camunda.com", - "license": "Apache 2.0", + "license": "Apache-2.0", "repository": { "type": "git", "url": "git+https://github.com/camunda/camunda-8-js-sdk.git" @@ -159,4 +159,4 @@ "typed-duration": "^1.0.12", "uuid": "^7.0.3" } -} +} \ No newline at end of file