Skip to content

Commit 41d0b4c

Browse files
Further improvements on the ReadMe
1 parent ee3a4c7 commit 41d0b4c

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# v1.2.2 (2019-05-04)
2+
3+
## Bug Fixes
4+
5+
* Corrected ReadMe information, closes [#97](https://github.com/dhlab-basel/json2typescript/issues/97)
6+
17
# v1.2.1 (2019-05-02)
28

39
## Bug Fixes
@@ -13,7 +19,7 @@
1319
## Breaking Changes
1420

1521
* If a property is declared optional (by `@JsonProperty(name, Type, true)`), then `null` is now ignored in both serialization and deserialization.
16-
Before this version, `json2typescript` would have thrown an error if `ValueChecking.DISABLE_NULL` was used.
22+
Before this version, `json2typescript` would have thrown an error if `ValueChecking.DISALLOW_NULL` was used.
1723

1824
# v1.1.1 (2019-02-12)
1925

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ let user: User = jsonConvert.deserializeObject(jsonObj, User);
2626
console.log(user); // prints User{ ... } in JavaScript runtime, not Object{ ... }
2727
```
2828

29-
> Tip: All `serialize()` and `deserialize()` methods may throw an exception in case of failure.
30-
Make sure you catch the errors in production!
29+
> Tip: All `serialize()` and `deserialize()` methods may throw an `Error` in case of failure.
30+
Make sure you catch errors in production!
3131

3232
---
3333

@@ -220,7 +220,7 @@ export class AppComponent implements OnInit {
220220
// Map to the country class
221221
let country: Country;
222222
try {
223-
country = jsonConvert.deserialize(jsonObject, Country);
223+
country = jsonConvert.deserializeObject(jsonObject, Country);
224224
country.cities[0].printInfo(); // prints: Basel was founded in -200 and is really beautiful!
225225
} catch (e) {
226226
console.log((<Error>e));
@@ -326,7 +326,7 @@ See the examples at the end of this document for more info about nesting arrays.
326326
327327
##### Adding a custom converter
328328
329-
More advanced users may need to use custom converters. If you don't want
329+
More advanced users may need to use custom converters. If you want
330330
`json2typescript` to use your custom converter, you need to follow these
331331
steps:
332332
@@ -358,6 +358,10 @@ The type is still checked as soon the property is present again.
358358
359359
The same applies for the case when you try to serialize a TypeScript object to a JSON object. If the property is not defined in the class and optional, it will not be added to the JSON object.
360360
361+
> Tip: Some API's return null instead of omitting optional values.
362+
If you flag a property as optional, `json2typescript` will ignore null values and keep the default value of the property instead.
363+
This fact is particularly helpful if your project uses TypeScript `strictNullChecks` or/and disallows `null` values through the `valueCheckingMode` property in `json2typescript`.
364+
361365
#### Important notes
362366
363367
* Make sure you define the expected type as accurate as possible, even if you expect primitive types.
@@ -454,7 +458,9 @@ The default is `ValueCheckingMode.ALLOW_OBJECT_NULL`.
454458

455459
> Tip: Make sure you import the `ENUM` `ValueCheckingMode` when assigning a value to this property.
456460

457-
> Tip: The TypeScript developer team suggests you to avoid null values. If your JSON api doesn't return null values, you should try the last flag disallowing null values.
461+
> Tip: The TypeScript documentation suggests to avoid null values.
462+
Compile your TypeScript code with `strictNullChecks=true` and set the `valueCheckingMode` to disallow null values.
463+
If your API returns `null` in some cases, simply mark these properties as optional in the corresponding `JsonProperty` decorator to avoid errors on runtime.
458464

459465
#### Ignore primitive checks
460466

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json2typescript",
3-
"version": "1.2.1",
3+
"version": "1.2.2",
44
"description": "Provides TypeScript methods to map a JSON object to a JavaScript object on runtime",
55
"keywords": [
66
"convert",

0 commit comments

Comments
 (0)