Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persisting custom objects #42

Open
Miha-x64 opened this issue Mar 17, 2017 · 1 comment
Open

Persisting custom objects #42

Miha-x64 opened this issue Mar 17, 2017 · 1 comment

Comments

@Miha-x64
Copy link
Contributor

Hello again :)
What about supporting pref values, which could be presisted into String by custom converter?

object AppState { // client code
    val user by customPref<User?>(default = null, converter = UserConverter)
}

interface PrefConverter<T> { // library code
    fun fromPref(str: String): T
    fun toPref(t: T): String
}

object UserConverter : PrefConverter<User> { // client code
    private val gson = Gson()
    override fun fromPref(str: String) = gson.fromJson(str, User::class.java)
    override fun toPref(t: T) = gson.toJson(t)
}

Many ORMs (Hibernate, GreenDAO, ORMLite, ObjectBox, etc) do this for object's fields, so we can borrow some architectural solutions from them.

@chibatching
Copy link
Owner

I don't have the plan to support custom converter, but your idea is interesting.
I'll investigate it. Thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants