1 |
|
2 |
|
3 |
|
4 |
|
5 | "use strict";
|
6 |
|
7 | const { register } = require("./serialization");
|
8 |
|
9 | class ClassSerializer {
|
10 | constructor(Constructor) {
|
11 | this.Constructor = Constructor;
|
12 | }
|
13 |
|
14 | serialize(obj, context) {
|
15 | obj.serialize(context);
|
16 | }
|
17 |
|
18 | deserialize(context) {
|
19 | if (typeof this.Constructor.deserialize === "function") {
|
20 | return this.Constructor.deserialize(context);
|
21 | }
|
22 | const obj = new this.Constructor();
|
23 | obj.deserialize(context);
|
24 | return obj;
|
25 | }
|
26 | }
|
27 |
|
28 | module.exports = (Constructor, request, name = null) => {
|
29 | register(Constructor, request, name, new ClassSerializer(Constructor));
|
30 | };
|