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

Boilerplate code - Declaring Codecs often requires more Codecs #7

Closed
MarconZet opened this issue Apr 19, 2021 · 6 comments
Closed

Boilerplate code - Declaring Codecs often requires more Codecs #7

MarconZet opened this issue Apr 19, 2021 · 6 comments
Assignees
Labels
usability Relates to reduction of boilerplate etc.

Comments

@MarconZet
Copy link
Collaborator

MarconZet commented Apr 19, 2021

When declaring Codec[A], if class A has a field of class B, then Codec[B] must also be declared.

@PawelLipski PawelLipski changed the title Boilerplate code - Declaring Codexes often requires more Codexes Boilerplate code - Declaring Codecs often requires more Codecs Apr 24, 2021
@PawelLipski PawelLipski mentioned this issue Apr 26, 2021
Merged
@PawelLipski
Copy link
Collaborator

Let's assess https://github.com/plokhotnyuk/jsoniter-scala in this context

@PawelLipski PawelLipski added the usability Relates to reduction of boilerplate etc. label Apr 27, 2021
@MarconZet
Copy link
Collaborator Author

Let's assess https://github.com/plokhotnyuk/jsoniter-scala in this context

Hmm...
Jsoniter philosophy seams difrent form Borer.
JsonValueCodec[A] is "fat". It contains all information required to serialize and deserialise class.
Borer's codeces are more like layers. One codex feeds into another, breaking down object into simpler and simpler elements.

@PawelLipski
Copy link
Collaborator

Hmmm okay but jsoniter claims that it can cooperate with Borer somehow (generate Borer-compatible codecs?)... this is probably going to be useful for our use case (?)

@PawelLipski
Copy link
Collaborator

@sirthias can you think of any ready solution here? Like jsoniter-scala or sth else Magnolia-based?

@sirthias
Copy link

sirthias commented Apr 28, 2021

borer derivation is intentionally not fully "auto-magic", because this often leads to issues down the road.
See this ticket for example: softwaremill/magnolia#79

Consider this snippet for example:

case class Foo(int: Int, qux: Qux)
case class Bar(qux: Qux)
case class Qux(...)

If deriveCodec[Foo] would automatically also derive the codec for Qux then this Codec[Qux] wouldn't be visible during derivation of Codec[Bar]! Which means that deriveCodec[Bar] would generate Codec[Qux] again!
And you wouldn't see this duplication anywhere!

In this small example this might not be an issue but for large model hierarchies these kinds of invisible duplications can create huge amounts of code, that takes a long time to compile and can create a number of strange issues.

In our experience it's indeed better to manually cache codecs for all types in implicit vals, which takes only a single line.
This results in the minimal amount of code, fastest compilation and runtime performance as well as full transparency on which type classes are actually available and which aren't.

@PawelLipski
Copy link
Collaborator

Okay, that's a valuable point... so maybe we @MarconZet should not go down this rabbit hole indeed, and instead focus on #5 to prevent runtime errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
usability Relates to reduction of boilerplate etc.
Projects
None yet
Development

No branches or pull requests

3 participants