Skip to content

Commit 61bba02

Browse files
committed
feat(rest-crud): use deepkit deserialization in entity serializer
1 parent 6efd7a8 commit 61bba02

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

packages/rest-crud/src/rest-serialization.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ClassType } from "@deepkit/core";
22
import {
3+
deserialize,
34
NamingStrategy,
45
ReflectionClass,
56
SerializationOptions,
@@ -100,12 +101,9 @@ export class RestGenericSerializer<Entity>
100101

101102
protected createEntity(data: Partial<Entity>): Entity {
102103
const entityType = this.context.getEntitySchema().getClassType();
103-
if (entityType.length) {
104-
const message =
105-
"Entity constructor should take no params for generic creation";
106-
throw new Error(message);
107-
}
108-
const entity: Entity = new entityType();
104+
const instantiate = () =>
105+
deserialize(data, undefined, undefined, undefined, entityType);
106+
const entity = instantiate();
109107
Object.assign(entity, data);
110108
return entity;
111109
}

0 commit comments

Comments
 (0)