Last active
September 15, 2019 02:52
-
-
Save Lzyct/439cda216ac0fbba568e89382e27ac38 to your computer and use it in GitHub Desktop.
Save and Load Object in SharedPreference with Moshi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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