-
Notifications
You must be signed in to change notification settings - Fork 146
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
fix: default case class values memoized #1119
Open
Andrapyre
wants to merge
10
commits into
zio:series/2.x
Choose a base branch
from
Andrapyre:fixing-default
base: series/2.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@jdegoes , while this is waiting for upstream dependencies to upgrade to Scala Native |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR closes #1055 and, in the process, updates
zio-json
to the Scala Native0.5.x
series (necessary because this requires multiple PRs to Magnolia and Magnolia is already on the0.5.x
series). Since the move to the Scala Native0.5.x
series was a small ecosystem change, it required most dependencies to be updated to the latest versions. It also required a slight downgrade to the7.2.x
series in the scalaz dependency, since the7.3.x
series does not yet support Scala Native.The solution does the following things:
For each default parameter, it computes two values at build time. If the values are the same, the default parameter will be memoized. If the values are different, the default value will be computed during json parsing.
The above provides out-of-the-box support for random generators which are always random (like
java.util.UUID
). However, random time-based generators are not always random, since they can be called at the same time or near enough to the same time to render the same result twice. Therefore, this solution does not memoize default values of any class that extendsjava.time.temporal.Temporal
- default values for all of the following will be computed during json parsing:For all random generators that are not truly random and are outside of the above classes, this solution introduces a
@jsonAlwaysEvaluateDefault
annotation so that users can manually force evaluation of the default parameter every time json is parsed (especially relevant for timestamp values coming from 3rd party libs, e.g.org.joda.time
).The result is that users can implement the following case class and expect the results for each parameter as described in the comments:
External dependencies
Several external dependencies need to be closed before this will build in Github Actions:
The core ZIO libraries need to be upgraded to Scala Native0.5.x
. This can be started once upstream dependencies are upgraded. Publish for Scala native 0.5 zio#8786Thescala-java-time
lib needs to be upgraded to Scala Native0.5.x
. Scala Native 0.5.x cquiroz/scala-java-time#508One PR needs to be merged into the Magnolia Scala2.x
series. [scala2] feat: adding on-demand default evaluation softwaremill/magnolia#533One PR needs to be merged into the Magnolia Scala3.x
series. feat: adding on-demand default evaluation softwaremill/magnolia#534/claim #1055