Skip to content

Commit

Permalink
Further improvements on the ReadMe
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-aeschlimann committed May 4, 2019
1 parent ee3a4c7 commit 41d0b4c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v1.2.2 (2019-05-04)

## Bug Fixes

* Corrected ReadMe information, closes [#97](https://github.com/dhlab-basel/json2typescript/issues/97)

# v1.2.1 (2019-05-02)

## Bug Fixes
Expand All @@ -13,7 +19,7 @@
## Breaking Changes

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

# v1.1.1 (2019-02-12)

Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ let user: User = jsonConvert.deserializeObject(jsonObj, User);
console.log(user); // prints User{ ... } in JavaScript runtime, not Object{ ... }
```

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

---

Expand Down Expand Up @@ -220,7 +220,7 @@ export class AppComponent implements OnInit {
// Map to the country class
let country: Country;
try {
country = jsonConvert.deserialize(jsonObject, Country);
country = jsonConvert.deserializeObject(jsonObject, Country);
country.cities[0].printInfo(); // prints: Basel was founded in -200 and is really beautiful!
} catch (e) {
console.log((<Error>e));
Expand Down Expand Up @@ -326,7 +326,7 @@ See the examples at the end of this document for more info about nesting arrays.
##### Adding a custom converter
More advanced users may need to use custom converters. If you don't want
More advanced users may need to use custom converters. If you want
`json2typescript` to use your custom converter, you need to follow these
steps:
Expand Down Expand Up @@ -358,6 +358,10 @@ The type is still checked as soon the property is present again.
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.
> Tip: Some API's return null instead of omitting optional values.
If you flag a property as optional, `json2typescript` will ignore null values and keep the default value of the property instead.
This fact is particularly helpful if your project uses TypeScript `strictNullChecks` or/and disallows `null` values through the `valueCheckingMode` property in `json2typescript`.
#### Important notes
* Make sure you define the expected type as accurate as possible, even if you expect primitive types.
Expand Down Expand Up @@ -454,7 +458,9 @@ The default is `ValueCheckingMode.ALLOW_OBJECT_NULL`.

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

> 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.
> Tip: The TypeScript documentation suggests to avoid null values.
Compile your TypeScript code with `strictNullChecks=true` and set the `valueCheckingMode` to disallow null values.
If your API returns `null` in some cases, simply mark these properties as optional in the corresponding `JsonProperty` decorator to avoid errors on runtime.

#### Ignore primitive checks

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "json2typescript",
"version": "1.2.1",
"version": "1.2.2",
"description": "Provides TypeScript methods to map a JSON object to a JavaScript object on runtime",
"keywords": [
"convert",
Expand Down

0 comments on commit 41d0b4c

Please sign in to comment.