Skip to content

Instantly share code, notes, and snippets.

@Lzyct
Last active September 15, 2019 02:52
Show Gist options
  • Select an option

  • Save Lzyct/439cda216ac0fbba568e89382e27ac38 to your computer and use it in GitHub Desktop.

Select an option

Save Lzyct/439cda216ac0fbba568e89382e27ac38 to your computer and use it in GitHub Desktop.
Save and Load Object in SharedPreference with Moshi
//save object as json
val adapter = Moshi.Builder().build().adapter(SavedObject::class.java)
val json = adapter.toJson(it.data?.body()?.result)
prefManager.saveString("Saved Object", json)
//load object
val objectJson = prefManager.getString("Saved Object")
val adapter = Moshi.Builder().build().adapter(SavedObject::class.java)
val result = adapter.fromJson(objectJson)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment