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/package.json b/package.json index 78a2afa3..9f6328e1 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 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) => {