-
Notifications
You must be signed in to change notification settings - Fork 32
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
Optional nested beans support for join results #94
Draft
hpgliniecki
wants to merge
12
commits into
master
Choose a base branch
from
nested-optional-prototype
base: master
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.
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
hpgliniecki
requested review from
suruuK,
stevie400,
kmclarnon,
Xcelled and
jaredstehler
June 2, 2023 13:43
jaredstehler
reviewed
Jun 3, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be nice if you could add a test in the jdbi3
package showing this with an actual left join?
I agree, without a test case I think it's hard to see the utility here. |
…or a view object which fetches the entire optional nested object instead two separate optional fields. This pays off even more with a greater number of fields in the nested object, and when the nested object is subtyped.
I've provided two test cases:
|
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
The proposed feature deals with deserialisation of optional nested beans, which is required when dealing with a result of a
LEFT JOIN
and view beans.The Problem
Let's suppose we've got two tables for
Foo
andBar
objects namelyfoos
andbars
, we'd like to fetch a view objectFooBar
which is a result of a:while the bean itself has the following structure:
Naturally, we might not find some
Bar
s however the result of the query will be a json of the form:which will result in a deserialisation error of the
Optional<Bar>
as for it to work correctly it would need to get eithernull
or nobar
at all.Currently, we would need to use an intermediate structure to fetch the results, including an 'all Optional' version of
Bar
:which for more verbose objects may be cumbersome.
Proposed Solution
This PR introduces the
NestedOptionalDeserializer<>
which checks whether all fields arenull
and if it is the case, provides an emptyOptional<>
as a result, so that intermediate structures are no longer necessary.In other words, the deserializer will treat:
as if the following has been given for deserialization:
iff all of the
bar
properties arenull
and thebar
field is marked with the@NestedOptional
annotation.The annotation is introduced so that
Rosetta
can recognise that the above rule should be applied, providing a simple way to control this behavior.WIP
Please note, this PR is only a bare minimum to illustrate the issue and a possible solution, so the tests and the naming are likely to change - also, additional effort will be put forward to check the performance of the changes if the proposal is accepted.