-
Notifications
You must be signed in to change notification settings - Fork 28
Closed
Description
I am writing Dserializable
abstract class which indicate it can be deserialized and has deserialize
Function. It looks like
const cerialize = require('cerialize'); // import
abstract class Deserializable {
public static deserialize<T> (json, constructor): T {
return cerialize.Deserialize(json, constructor);
}
}
// usage
class Command extends Deserializable {
@deserialize public help: boolean;
@deserializeAs(CommandOrder, "_order") public orders: Array<CommandOrder>;
@deserializeAs("_args") public args: Array<String>;
}
let cmd = Command.deserialize<Command>(json, Command);
But since cerialize.Deserialize
requires the constructor function as the second arg, It's somewhat verbose.
If we have a type parameterized cerialize.Deserialize
function, we can make more simplified Deserialzable
. For example,
export abstract class Deserializable {
public static deserialize<T> (json): T {
return Deserialize<T>(json);
}
}
// more simple
Command.deserialize<Command>(json);
Thanks. :)
Metadata
Metadata
Assignees
Labels
No labels