December 2017
Intermediate to advanced
260 pages
7h 34m
English
We will implement the JsonModel interface to facilitate the conversion between JSON and the domain classes, for which we will need to override two functions—updateModel and toJSON.
The updateModel function is called to convert the JSON object to the domain model. It receives a JSON object as a parameter from which we update the properties of our domain model object. Let's take a look at the following example:
override fun updateModel(json: JsonObject) { with(json) { word = string("word") definitions.setAll(getJsonArray("definitions").toModel()) } }
The toJSON function is called to convert the domain model object to a JSON payload. It receives JsonBuilder as a parameter where we set the values of the model ...
Read now
Unlock full access