Wrapper over GenCodec which forces fully automatic derivation.
If you ask for implicit value of type GenCodec[T], the codec must be explicitly declared and imported or
put into implicit scope (e.g. companion object of T), even though it can be automatically implemented
using materialize or materializeRecursively.
However, if you ask for implicit value of type GenCodec.Auto[T], the compiler will always fall back to fully
automatic derivation if it cannot find already declared GenCodec. Note that since GenCodec.Auto will always
try to wrap already existing GenCodec (if there is one), you should never explicitly declare any instances
of GenCodec.Auto. If you need custom serialization, just write a GenCodec and GenCodec.Auto will wrap it.
Whether you want to use GenCodec or GenCodec.Auto depends on your use case. GenCodec should be generally
used when you want the programmer to always explicitly state that some type is serializable. For example, if you
serialize your objects in order to put them into database, you probably want to use GenCodec and not GenCodec.Auto,
because every type that has been written to database is likely to be bound by backwards compatibility constraints and
cannot be freely refactored. That's why you want to always explicitly make the decision of making a type serializable.
Wrapper over
GenCodec
which forces fully automatic derivation.If you ask for implicit value of type
GenCodec[T]
, the codec must be explicitly declared and imported or put into implicit scope (e.g. companion object ofT
), even though it can be automatically implemented usingmaterialize
ormaterializeRecursively
.However, if you ask for implicit value of type
GenCodec.Auto[T]
, the compiler will always fall back to fully automatic derivation if it cannot find already declaredGenCodec
. Note that sinceGenCodec.Auto
will always try to wrap already existingGenCodec
(if there is one), you should never explicitly declare any instances ofGenCodec.Auto
. If you need custom serialization, just write aGenCodec
andGenCodec.Auto
will wrap it.Whether you want to use
GenCodec
orGenCodec.Auto
depends on your use case.GenCodec
should be generally used when you want the programmer to always explicitly state that some type is serializable. For example, if you serialize your objects in order to put them into database, you probably want to useGenCodec
and notGenCodec.Auto
, because every type that has been written to database is likely to be bound by backwards compatibility constraints and cannot be freely refactored. That's why you want to always explicitly make the decision of making a type serializable.