Last active
October 10, 2019 16:44
-
-
Save antsmartian/e1ea8cf4fa8052ebd4f95508f39f4800 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// import {plainToClass} from "class-transformer"; | |
require("@babel/core").transform("code", { | |
plugins: ["@babel/plugin-proposal-decorators"] | |
}); | |
/* | |
{ | |
"id": 1, | |
"firstName": "Johny", | |
"lastName": "Cage", | |
"age": 27, | |
"nested" : { | |
"key" : "value" | |
} | |
} | |
*/ | |
const plainToClass = require("class-transformer").plainToClass; | |
const Type = require("class-transformer").Type | |
const userJson = require("./test.json"); | |
var reflectMetadata = require('reflect-metadata'); | |
class Nested { | |
constructor(data) { | |
this.key = null; | |
} | |
} | |
class User { | |
constructor() { | |
this.id = null; | |
this.firstName = null; | |
this.lastName = null; | |
// decoratorsBeforeExport: true | |
@Type(() => Nested) | |
this.nested = null | |
} | |
getId() { | |
return this.id | |
} | |
} | |
let users = plainToClass(User, userJson); | |
// console.log("users are ", users.getNested()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment