I took a swing at implementing this a few weeks before this thread, actually (I didn't see it at the time). You can see the results here: https://github.com/sgrif/scala-android-parceling. The library works by creating a case class responsible for parceling a type, and using shapeless' auto-deriving type classes to make it work for arbitrary case classes.
It still requires 2 lines of boilerplate, but I'm sure you could easily get rid of those with a macro. This is an example of an actual case class which can be parceled. https://github.com/sgrif/scala-android-parceling/blob/master/src/test/scala/ParceledTest.scala#L35-L41 On Wednesday, October 22, 2014 at 8:17:22 AM UTC-6, Nick Stanchenko wrote: > > Maybe I’ll give it a go, but right now I don’t have any time :( If you do > it first, make sure to submit a pull request to Macroid ;) > > Nick > > On Wednesday, October 22, 2014 2:50:49 PM UTC+1, David Pérez wrote: >> >> Thanks Nick, your tip is valuable. >> >> Am Mittwoch, 22. Oktober 2014 15:33:14 UTC+2 schrieb Nick Stanchenko: >>> >>> 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 scala-on-android+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.