Hi,
It should be relatively straightforward if you know your way around macros
:)
Here’s one that serializes pairs (key,
value):
https://github.com/macroid/macroid/blob/master/src/main/scala/macroid/Bundles.scala#L24
>From there, you just need to add the case class inspection bit. Example (a
bit
convoluted):
https://github.com/jto/validation/blob/master/validation-core/src/main/scala/play/api/data/mapping/MappingMacros.scala#L41,
see also line 89 for usage.
On a final note, I would make it typeclass-based rather than
inheritance-based:
trait Bundleable[A] {
def toBundle(x: A): Bundle
def fromBundle(b: Bundle): Try[A]
}
implicit def genBundleable[A]: Bundleable[A] = macro ???
def bundle[A: Bundleable](x: A) =
implicitly[Bundleable[A]].toBundle(x)
This way you can define instances of Bundleable[A] both manually and
automatically. And your data model is not polluted with Android nonsense.
Hope that helps,
Nick
On Wednesday, October 22, 2014 8:06:44 AM UTC+1, David Pérez wrote:
>
> Hi all,
>
> I've made recently this StackOverflow question:
>
>
> http://stackoverflow.com/questions/26501968/deserializing-objects-automatically-to-a-bundle
>
> Any answers and/or clues will be welcome.
>
> David
>
--
You received this message because you are subscribed to the Google Groups
"scala-on-android" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.