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