-
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 #2 from edcarroll/develop
v1.1.0 into Master
- Loading branch information
Showing
17 changed files
with
262 additions
and
70 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,4 +1,38 @@ | ||
export * from "./lib/json"; | ||
export * from "./lib/types"; | ||
export * from "./lib/decorators"; | ||
export * from "./lib/converters"; | ||
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)); // |
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
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,7 @@ | ||
import {getDefinition} from '../classes/object-definition'; | ||
|
||
export function JsonDiscriminatorProperty(property:string) { | ||
return function(constructor:Function):void { | ||
getDefinition(constructor).discriminatorProperty = property; | ||
}; | ||
} |
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,7 @@ | ||
import {getDefinition} from '../classes/object-definition'; | ||
|
||
export function JsonDiscriminatorValue(value:any) { | ||
return function(constructor:Function):void { | ||
getDefinition(constructor).discriminatorValue = value; | ||
}; | ||
} |
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
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 JsonWriteonly() { | ||
return function(target:any, key:string):void { | ||
const property = getDefinition(target.constructor).getProperty(key); | ||
|
||
property.writeonly = true; | ||
}; | ||
} |
Oops, something went wrong.