Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Adds lazy to implicit Encoder vals #169

Merged
merged 1 commit into from
Jul 8, 2022
Merged

Adds lazy to implicit Encoder vals #169

merged 1 commit into from
Jul 8, 2022

Conversation

alycklama
Copy link
Contributor

The implicit val encoderX ... need to become lazy, as the hierarchy matters:

case class Organization(owner: Person)
case class Person(name: String)

implicit val encoderOrganization: Encoder[Organization] = ...
implicit val encoderPerson: Encoder[Person] = ...

The above will throw a NullPointerException once you start encoding an Organization.

@ghostbuster91
Copy link
Owner

You are right. Probably the proper way to fix that would be to analyze dependencies between products and generate them in a way that takes that into account. Although, that would be a lot of work.

As a first implementation your solution is good enough 👍

@ghostbuster91 ghostbuster91 merged commit c9b9b99 into ghostbuster91:master Jul 8, 2022
@ghostbuster91
Copy link
Owner

Thank you for the contribution! 🎉

@alycklama
Copy link
Contributor Author

You're welcome!

The dependencies could be analyzed, though I'm wonder what the added benefit is? The lazy keyword does this dependency resolution automatically for you. I don't believe there's any performance penalty to take into consideration here either for using lazy.

@ghostbuster91
Copy link
Owner

I like my generated code to be as efficient as possible even if the difference is negligible (e.g. lazy generates more bytecode). However, we should also take into account future maintenance and it is definitely easier to maintain a code that hasn't been written at all. So, fair point and I agree.

@ghostbuster91
Copy link
Owner

Published as 0.3.0 😄

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

Successfully merging this pull request may close these issues.

2 participants