Getting ready

Similar to the interface delegation, the class property delegation is achieved using the by keyword in the following manner:

class MyClass {
var property: String by MyDelegate
}

The object which is delegated to should implement one of the following interfaces—ReadWriteProperty or ReadOnlyProperty from the kotlin.properties package. Those interfaces expose the getValue() and setValue() functions, which provide values for the property.

We are going to use the Gson library to convert objects into their JSON format representation. It's a widely used Java library for working with JSON-formatted objects.  You can learn more about the library on its GitHub site (https://github.com/google/gson). If you're using the Gradle build tool, you need to add the Gson artifact to the project dependencies: 

dependencies {
    implementation 'com.google.code.gson:gson:2.8.4'
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.62.29