I actually used Realm in the past for this specific project and I ended up overengineering and migrating back to SharedPreferences eventually anyway. In my case the data is really simple and it's a small set. If you have a complicated, large set of data you really should be using Room or Realm - or something else along those lines. In my specific case I had a data class that I wanted to save to SharedPreferences. There are a few reasons why you might want to use Serialization. I'm going to specifically write about JSON serialization. Today I thought I'd write a quick post about using Kotlin Serialization in an Android project. Android, Serialization, Kotlin - 1 min read This annotation instructs the framework to serialize the said property regardless of its value or configuration setting.Using Kotlin Serialization in an Android Project Instead, we use the annotation directly on the property having a default value. The second method we can use doesn’t require defining a configuration setting as in the first method. So, although the color property has a default value, by defining a configuration setting for JSON, we can have it encoded as well. Val jsonString = Json.encodeToString(car)ĪssertEquals("", jsonString) Now, we serialize the Car class val car = Car("Ford") Import class Car(val type: String, val color: String = "Blue")
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |