Skip to content

Initialize properties in deserialization example #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ Lets have a look at an example:
```typescript
class SimpleRoster {
@JsonProperty()
private name: String;
private name: String = undefined;
@JsonProperty()
private worksOnWeekend: Boolean;
private worksOnWeekend: Boolean = undefined;
@JsonProperty()
private numberOfHours: Number;
private numberOfHours: Number = undefined;
@JsonProperty({type:Date})
private systemDate: Date;
private systemDate: Date = undefined;

public isAvailableToday(): Boolean {
if (this.systemDate.getDay() % 6 == 0 && this.worksOnWeekend == false) {
Expand Down Expand Up @@ -83,6 +83,8 @@ a `Number` object and the `systemDate` field will be assinged a `Date` object wi
`Sat Dec 31, 2016`. The method will also make sure that all the nested object graphs has been
created based on the JSON model.

Note that initializing the properties is important (eg by assigning `undefined` at their declaration or in the constructor). Properties which are not initialized properly are not part of the keys-collection after object creation - therefore deserialization would not work as expected.

The `serialize` method will serialize an object graph into JSON string (similar to what `JSON.stringrify()`
method would do) while honoring the decorator metadata. Following is an example of serialization:

Expand Down