Search⌘ K

Serialization and Data Management in Model Code

Let’s learn how to write the serialization function and how to perform data management for the application.

Write a serialization function

The object serialization function toString() now needs to include the values of enumeration attributes.

Javascript (babel-node)
class Book {
...
toString() {
return "Book{ ISBN:" + this.isbn + ", title:" + this.title +
", originalLanguage:" + this.originalLanguage +
", otherAvailableLanguages:" +
this.otherAvailableLanguages.toString() +
", category:" + this.category +
", publicationForms:" +
this.publicationForms.toString() + "}";
}
...
}

Notice that for multi-valued enumeration attributes, we call the toString() function predefined for JS arrays.

Data

...