JairusSW/as-json

Classes which extend are missing parent encode statements

Closed this issue ยท 0 comments

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

When extending a class the parent class fields are not added to the decode statements (just encode).

Here is the diff that solved my problem:

diff --git a/node_modules/json-as/transform/lib/index.js b/node_modules/json-as/transform/lib/index.js
index 12837b0..e151df8 100755
--- a/node_modules/json-as/transform/lib/index.js
+++ b/node_modules/json-as/transform/lib/index.js
@@ -85,7 +85,9 @@ class AsJSONTransform extends BaseVisitor {
                 console.error("Class extends " + this.currentClass.parent + ", but parent class not found. Maybe add the @json decorator over parent class?");
             }
         }
-        this.visit(node.members);
+        const parentSchema = this.schemasList.find((v) => v.name == this.currentClass.parent);
+        const members = [...node.members, ...(parentSchema ? parentSchema.node.members : [])]
+        this.visit(members);
         let serializeFunc = "";
         if (this.currentClass.encodeStmts.length > 0) {
             const stmt = this.currentClass.encodeStmts[this.currentClass.encodeStmts.length - 1];