diff --git a/.yarn/install-state.gz b/.yarn/install-state.gz index 206b81c..b7da4fe 100644 Binary files a/.yarn/install-state.gz and b/.yarn/install-state.gz differ diff --git a/packages/arbor-json/src/Json.ts b/packages/arbor-json/src/Json.ts index 9736a27..004acb7 100644 --- a/packages/arbor-json/src/Json.ts +++ b/packages/arbor-json/src/Json.ts @@ -126,6 +126,8 @@ export class Json { } else if (Type) { const instance = new Type() return Object.assign(instance, value.$value) + } else { + throw new Error(`Unknown type: ${value.$type}. Can't deserialize.`) } } diff --git a/packages/arbor-json/tests/Json.test.ts b/packages/arbor-json/tests/Json.test.ts index d26728e..54c27ee 100644 --- a/packages/arbor-json/tests/Json.test.ts +++ b/packages/arbor-json/tests/Json.test.ts @@ -110,6 +110,15 @@ describe("Json", () => { expect(deserialized).toBeInstanceOf(TodoList) expect(deserialized).toEqual(todoList) }) + + it("throws exception when custom type is not found", () => { + const serialized = + '{"$value":{"uuid":"a","text":"Clean the house"},"$type":"Task"}' + + expect(() => parse(serialized)).toThrow( + "Unknown type: Task. Can't deserialize." + ) + }) }) describe("custom type with custom $type key", () => {