|
| 1 | +# JavaScript Object Graphs with Typescript |
| 2 | + |
| 3 | +This Typescript module implements [JSOG format](https://github.com/jsog/jsog). |
| 4 | +It is able to instantiante typescript objects during deserialization. |
| 5 | + |
| 6 | +## Usage |
| 7 | + |
| 8 | +### Installation |
| 9 | + |
| 10 | +``` |
| 11 | +npm --save jsog-ts |
| 12 | +``` |
| 13 | + |
| 14 | +Enable typescript `experimentalDecorator` and `emitDecoratorMetadata` compiler options. |
| 15 | + |
| 16 | +Minimal tslint.json: |
| 17 | +``` |
| 18 | +{ |
| 19 | + "compilerOptions": { |
| 20 | + "experimentalDecorators": true, |
| 21 | + "emitDecoratorMetadata": true, |
| 22 | + } |
| 23 | +} |
| 24 | +``` |
| 25 | + |
| 26 | +### General |
| 27 | + |
| 28 | +Generate a new instance of the service. See Integration for integration to some popular frameworks. |
| 29 | + |
| 30 | +``` |
| 31 | +import { jsogService } from 'jsog-ts' |
| 32 | +
|
| 33 | +const jsog = new JsogService(); |
| 34 | +``` |
| 35 | + |
| 36 | +Use it to serialize and deserialize JavaScript Objects. |
| 37 | +``` |
| 38 | +jsog.serialize(javaScriptObject); |
| 39 | +jsog.deserialize(jsogObjectGraph); |
| 40 | +``` |
| 41 | + |
| 42 | +### Instatiate Typescript Objects |
| 43 | + |
| 44 | +Description how to instatiate Typescript objects to provide convinent methods and use the `typeof` operator. |
| 45 | + |
| 46 | +Instantiate the root object or a list of rootObjects: |
| 47 | +``` |
| 48 | +jsog.deserializeObject(jsogObjectGraph, ExampleClass); |
| 49 | +jsog.deserializeArray(jsogObjectArray, ExampleClass); |
| 50 | +``` |
| 51 | + |
| 52 | +To instantiate references somewhere in the tree decorate class properties to instantiate with `@JsonProperty()` and properties with Lists containing objects of type `ExamplecClass` use `@JsonProperty(ExampleClass)`. |
| 53 | + |
| 54 | +### Integration |
| 55 | + |
| 56 | +#### Angular 4 |
| 57 | + |
| 58 | +Provide JsogService as an Angular 4 Service which can be injected into your Components/Services. |
| 59 | + |
| 60 | +``` |
| 61 | +import { NgModule } from '@angular/core'; |
| 62 | +import { JsogService } from 'jsog-ts'; |
| 63 | +
|
| 64 | +@NgModule({ |
| 65 | + providers: [ |
| 66 | + JsogService |
| 67 | + ] |
| 68 | +)} |
| 69 | +``` |
| 70 | + |
| 71 | +#### AngularJs |
| 72 | + |
| 73 | +Register JsogService as an Angular Service |
| 74 | + |
| 75 | +``` |
| 76 | +import { module } from 'angular'; |
| 77 | +import { JsogService } from 'jsog-ts'; |
| 78 | +
|
| 79 | +module.service('JsogService', JsogService) |
| 80 | +``` |
| 81 | + |
| 82 | +## Developer Guide |
| 83 | + |
| 84 | +### System dependencies |
| 85 | +- [npm](https://www.npmjs.com/) (4.6.1) |
| 86 | + |
| 87 | +## Author |
| 88 | + |
| 89 | +* Simon Nagl (simon.nagl@e-mundo.de) |
| 90 | + |
| 91 | +## License |
| 92 | + |
| 93 | +This software is provided under the [MIT license](http://opensource.org/licenses/MIT) |
| 94 | + |
| 95 | +This software uses code and ideas from: |
| 96 | + |
| 97 | +- [JSOG - JavaScript Object Graph](https://github.com/jsog/jsog) |
| 98 | +- [json-typescript-mapper](https://github.com/jf3096/json-typescript-mapper) |
0 commit comments