Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

full auto derivation #55

Open
kailuowang opened this issue Feb 2, 2018 · 2 comments
Open

full auto derivation #55

kailuowang opened this issue Feb 2, 2018 · 2 comments

Comments

@kailuowang
Copy link

As of now, if you have a nested tree of case classes for example

case class A(a: String)
case class B(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.

@julienrf
Copy link
Owner

julienrf commented Feb 2, 2018

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.

What do you think?

@kailuowang
Copy link
Author

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. )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants