-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from edcarroll/develop
v2.1.0 into Master
- Loading branch information
Showing
9 changed files
with
76 additions
and
55 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,4 @@ | ||
export * from "./lib/json"; | ||
export * from "./lib/types"; | ||
export * from "./lib/decorators"; | ||
export * from "./lib/converters"; | ||
|
||
import {JSON} from "./lib/json"; | ||
import {JsonObject, JsonDiscriminatorProperty, JsonProperty, JsonDiscriminatorValue} from "./lib/decorators"; | ||
|
||
export enum AnimalType { Cat = 0, Dog = 1 } | ||
|
||
@JsonObject() | ||
@JsonDiscriminatorProperty("type") | ||
export class Animal { | ||
@JsonProperty() | ||
type:AnimalType; | ||
} | ||
|
||
@JsonObject() | ||
@JsonDiscriminatorValue(AnimalType.Cat) | ||
export class Cat extends Animal { | ||
constructor() { | ||
super(); | ||
this.type = AnimalType.Cat; | ||
} | ||
} | ||
|
||
@JsonObject() | ||
@JsonDiscriminatorValue(AnimalType.Dog) | ||
export class Dog extends Animal { | ||
constructor() { | ||
super(); | ||
this.type = AnimalType.Dog; | ||
} | ||
} | ||
|
||
let animals = [new Cat(), new Dog()]; | ||
|
||
console.log(JSON.parse<Animal[]>('[{"type":0},{"type":1}]', Animal)); // | ||
export * from "./lib/converters"; |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {getDefinition} from '../classes/object-definition'; | ||
|
||
export function JsonConstructor() { | ||
return function(target:any, key:string):void { | ||
const definition = getDefinition(target.constructor); | ||
|
||
definition.ctr = target[key]; | ||
}; | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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