You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As of now, if you have a nested tree of case classes for example
caseclassA(a: String)
caseclassB(a: Option[A])
You would have to write a derived instance for each class.
In kittens, @joroKr21 developed a technique (with some facilities he added to shapeless 2.3.3), we can achieve full auto derivation.
Using the same technique, a single import will provide Format instant for all case classes, while still taking a lower priority than any other existing instances. In the example above, this technique generate Format instances for B and A but respect the existing instance for Option.
It's very easy to implement here with very few code change. (mostly just need to replace your Lazy[Writes[H]] with a Writes[H] OrElse DerivedOWrites[H] in here
If you are interested I can submit a PR. Let me know.
The text was updated successfully, but these errors were encountered:
I’m not a big fan of full auto derivation to be honest. I think it’s better to explicitly show what is going to be serialized (ie every type X that has an implicit Format[X] in its companion). Also, are the results of full derivation cached by the compiler? I’m afraid this can cause compile time issues.
That being said, if people want this feature I’m happy to support it under a different import than the current “semi auto” derivation.
Being able to know explicitly what are being serialized is definitely useful. At kittens we also provide "semi auto" derivation alone side the full auto one. The full auto one can be cached using shapeless.Cached (I didn't realize it until you mentioned, so I am adding it to kittens, Thanks!).
For my current use case, I can live with either way. And it seems that you don't have a use case for full auto. I guess we can defer this to whoever really needs an full auto derivation ( I can imagine some user may need it for an external big ADT that they don't want to be too coupled with. )
As of now, if you have a nested tree of case classes for example
You would have to write a derived instance for each class.
In kittens, @joroKr21 developed a technique (with some facilities he added to shapeless 2.3.3), we can achieve full auto derivation.
Using the same technique, a single
import
will provide Format instant for all case classes, while still taking a lower priority than any other existing instances. In the example above, this technique generateFormat
instances forB
andA
but respect the existing instance forOption
.It's very easy to implement here with very few code change. (mostly just need to replace your
Lazy[Writes[H]]
with aWrites[H] OrElse DerivedOWrites[H]
in hereIf you are interested I can submit a PR. Let me know.
The text was updated successfully, but these errors were encountered: