Reputation: 1096
I have two CodecRegistry implementation for a set of case classes. Most of them are created with macros. Now if I use the RegistryOne
only, it works for set "One" - the classes from package one
.
object RegistryOne {
lazy val registry: CodecRegistry =
fromRegistries(
fromCodecs(..),
fromProviders(..),
DEFAULT_CODEC_REGISTRY
)
}
object RegistryTwo {
lazy val registry: CodecRegistry =
fromRegistries(
fromCodecs(..),
fromProviders(..),
RegistryOne.registry,
DEFAULT_CODEC_REGISTRY
)
}
Some of classes implemented in RegistryTwo
are depending on package one
. So I just included the RegistryOne
into it. Now all serialization still works with RegistryTwo.registry
for set "One". But for the classes of package two
I get a runtime exceptions "Can't find a codec for class scala.Option". Seems like the DEFAULT_CODEC_REGISTRY
is not included in resulted registry?!
I have also RegistryThree
and RegistryFour
. At least for clarity and for future refactorings I would hold them separately.
How to combine the codec registries properly?
Upvotes: 1
Views: 238
Reputation: 1096
Turns out the error message is misleading. The macro for ADT main class also creates codecs for each subclass. If you also add a macro-created codec for one of them then the registry is confused and can't deserialize primitive things like scala.Option
.
Upvotes: 1