Skip to content

Commit ae111eb

Browse files
author
°¬Â×
committed
Release 1.1.1
1 parent b3f8c77 commit ae111eb

File tree

7 files changed

+31
-17
lines changed

7 files changed

+31
-17
lines changed

Diff for: .gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.js linguist-language=Typescript
2+
*.css linguist-language=Typescript
3+
*.html linguist-language=Typescript

Diff for: README.md

+18-9
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ npm install json-typescript-mapper --save
2525
import {deserialize} from 'json-typescript-mapper';
2626

2727
deserialize(<Class Type>, <JSON Object>);
28+
serialize(<Object>);
2829
```
2930

3031
## Example
3132
Here is a complex example, hopefully could give you an idea of how to use it (for more on how to use, checkout /spec which are unit test cases):
3233

33-
```bash
34+
```typescript
3435
class Student {
3536
@JsonProperty('name')
3637
fullName:string;
@@ -79,7 +80,7 @@ class Person {
7980
```
8081

8182
Now here is what API server return, assume it is already parsed to JSON object.
82-
```bash
83+
```typescript
8384
let json = {
8485
"Name": "Mark",
8586
"xing": "Galea",
@@ -114,15 +115,21 @@ let json = {
114115
115116
Simply, just map it use following code. The mapping is based on <@JsonProperty> decorator meta data.
116117
117-
```bash
118+
```typescript
118119
const person = deserialize(Person, json);
119120
```
120121
122+
If you want to reverse the action, from the other way round:
123+
124+
```typescript
125+
const json = serialize(person);
126+
```
127+
121128
## Notice
122129
Remember to add: <b>experimentalDecorators</b> and <b>emitDecoratorMetadata</b> in your tsconfig.json.
123130
This is essential to enable decorator support for your typescript program. Example shown as followings:
124131
125-
```bash
132+
```json
126133
{
127134
"compilerOptions": {
128135
"module": "commonjs",
@@ -145,10 +152,12 @@ The test case will be covered in the next push. This caused by inconsistent retu
145152
therefore I updated all null value to void 0 which is a better expression than undefined (idea from underscore source code).
146153
Most cases it won't affect previous version at all.
147154
155+
## Contributor
156+
@dankmo
148157
149-
## Roadmap:
150-
1) Fully json mapping to the modal class convention should be provided.
151-
If any unmapped variable discover, throw exception!
152-
This could be useful to detect if API data has change it data structure in the unit testing phrase.
158+
## ChangeLog
159+
#### 2017-02-20
153160
154-
2) Runtime data type validation might be a good idea. Alternatively, if this feature is not covered in the future, I will make use of json schema concept instead.
161+
**json-typescript-mapper** 1.1.0
162+
- Added serialized function
163+
- Passed more unit tests

Diff for: index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'reflect-metadata';
22
import {isTargetType, isPrimitiveOrPrimitiveClass, isArrayOrArrayClass} from './libs/utils';
3-
import {IDecoratorMetaData} from './';
43

54
/**
65
* provide interface to indicate the object is allowed to be traversed

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json-typescript-mapper",
3-
"version": "1.0.4",
3+
"version": "1.1.1",
44
"typescript": {
55
"definition": "index.d.ts"
66
},

Diff for: spec/common/dateconverter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ const dateConverter: ICustomConverter = {
1010
}
1111
};
1212

13-
export default dateConverter;
13+
export default dateConverter;

Diff for: spec/serialize.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('serialize', function () {
1010
name: string = undefined;
1111
}
1212
const instance = new ClassWithPrimitiveProp();
13-
instance.name = 'Jim';
13+
instance.name = 'Jim';
1414
const serializedInstance = serialize(instance);
1515
expect(serializedInstance.theName).to.equal('Jim');
1616
});
@@ -31,7 +31,6 @@ describe('serialize', function () {
3131
expect(serializedInstance.someProp).to.equal(primitiveType);
3232
});
3333
});
34-
3534
});
3635

3736
it('should keep unspecified objects as is', function () {
@@ -59,7 +58,7 @@ describe('serialize', function () {
5958
@JsonProperty('name')
6059
name: string = 'John';
6160

62-
@JsonProperty({ name: 'lastName', excludeToJson: true})
61+
@JsonProperty({name: 'lastName', excludeToJson: true})
6362
lastName: string = 'Doe';
6463
}
6564
const instance = new ClassWithExcludedProp();
@@ -74,7 +73,7 @@ describe('serialize', function () {
7473
date: Date = new Date();
7574
}
7675
class ClassWithClassProp {
77-
@JsonProperty({ name: 'other', clazz: OtherClass})
76+
@JsonProperty({name: 'other', clazz: OtherClass})
7877
other: OtherClass = new OtherClass();
7978
}
8079
const instance = new ClassWithClassProp();
@@ -113,5 +112,4 @@ describe('serialize', function () {
113112
expect(serializedInstance.items[1].date).to.equal('some-date');
114113
});
115114
});
116-
117115
});

Diff for: typings.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"globalDependencies": {
3+
"reflect-metadata": "registry:dt/reflect-metadata#0.0.0+20161005184000"
4+
}
5+
}

0 commit comments

Comments
 (0)