Autogenerate a Pickler.
Autogenerate a Pickler. See the documentation in the project's README.md.
Works like Autogen.apply[T]
.
Works like Autogen.apply[T]
. T must be a sealed trait or sealed abstract class.
The type argument Children
explicitly specifies the concrete sub-types of T that should be supported.
It is necessary to call this instead of Autogen.apply[T] when the macro call is made in the same compilation unit
where T is defined, due to SI-7588.
should be either a concrete subtype of T, or several types chained with the |
type, e.g. A | B | C
.
As children, but prints the generated code as a compiler informational message.
As children, but prints the generated code as a compiler informational message. Useful for debugging if the macro-generated code does not compile.
As apply, but prints the generated code as a compiler informational message.
As apply, but prints the generated code as a compiler informational message. Useful for debugging if the macro-generated code does not compile.
Generates a version compatibility bridge from the old version TOld
to the current version T
of the same type.
Generates a version compatibility bridge from the old version TOld
to the current version T
of the same type.
Suppose you want to make a backward-incompatible change to the type Foo. You should keep an unmodified copy of
the declaration of Foo; it doesn't have to include methods, just the fields necessary for pickling. Call this
unmodified copy OldFoo
.
Both OldFoo and Foo should have picklers defined, whether using Autogen or manually. The pickler for OldFoo must be the same as that which existed for Foo before it was modified.
Make OldFoo extend OldVersion[Foo]
, and implement the OldVersion.toNewVersion
method, which will convert an
OldFoo to the updated Foo.
Now change Foo's pickler definition to be Autogen.versioned[Foo, Foo, OldFoo]
.
The end result will be that the Pickler[Foo] generated by Autogen.versioned will be able to read pickled OldFoo values as well as pickled Foo values. Application code will always transparently receive Foo values. The pickler will only write Foo values, not OldFoo ones.
If you have more than old version of the same type, they should implemented the OldVersion trait in sequence, like so:
case class FooV1 extends OldVersion[FooV2] case class FooV2 extends OldVersion[FooV3] case class FooV3 extends OldVersion[Foo]
Autogen.versioned[Foo, FooV1]
The TOld
type parameter passed to Autogen.versioned should be the oldest version available. The macro will
follow the chain of OldVersion implementations until it reaches Foo.
As versioned, but prints the generated code as a compiler informational message.
As versioned, but prints the generated code as a compiler informational message. Useful for debugging if the macro-generated code does not compile.