scala / pickling

Fast, customizable, boilerplate-free pickling support for Scala
lampwww.epfl.ch/~hmiller/pickling
BSD 3-Clause "New" or "Revised" License
831 stars 79 forks source link

Improve custom pickler/unpickler generators #419

Closed jvican closed 8 years ago

jvican commented 8 years ago

This PR improves how custom pickler/unpickler generators are created in both scala pickling and third-party libraries that want to define their own for concrete types.

It also improves error reporting significantly. Now we have concrete exceptions for every kind of error that may happen. This improvement helps readability and also gives a pretty straightforward idea of what could go wrong.

List of changes:

Add custom runtime generators for Either

* Add custom runtime generators for Either and tests checking the new
 custom runtime generation.

* Make `AnyPicklerUnpickler` deal with more corner cases.

* Modify PicklingProtocol in sandbox-test and reuse it for both formats.

* Add error for disabled runtime generation.

* Improve the generator helper, make some renamings and add more
 documentation.

Refactor runtime custom picklers

* Remove some todos and make a better distinction between the runtime
 custom picklers and the runtime pickler registry. Merge the latter one
 in the `DefaultRuntimePicklerGenerator`.

* Improve some docs w.r.t. the runtime custom picklers.

* Make the `RuntimePicklerRegistry` more general for future custom
 picklers (like Either).

* Remove annoying prints when running tests.

Improve error reporting

* Keep compatibility with the same old API but improve significantly the
 way we report errors factoring out the most important ones and
 changing some of the error messages.

* Factor out the functionality to register pickler generators (to be
 used at runtime) and make easier to add new ones for the missing types.

* In tests, changes make sure that scala pickling is imported and that the
 deprecated method `generate` for Pickler and Unpickler is not used.

* Apply minor changes throughout scala pickling.
jsuereth commented 8 years ago

This looks pretty great, nice work! A few comments (mostly useless), but a few questions as well. Nothing that has to be handled now.

jvican commented 8 years ago

Thanks @jsuereth :smile: I'll address some stuff in my next PR. Currently, I'm trying to solve the scalajs problem and try these new changes with my custom picklers for spores! But I'll be doing this soon!