MINOR: Support java.util.Optional in the auto-generated protocol#9085
Closed
dajac wants to merge 1 commit intoapache:trunkfrom
Closed
MINOR: Support java.util.Optional in the auto-generated protocol#9085dajac wants to merge 1 commit intoapache:trunkfrom
dajac wants to merge 1 commit intoapache:trunkfrom
Conversation
This was referenced Jul 27, 2020
Merged
3 tasks
Member
Author
|
PR is outdated. Closing it. |
This file contains hidden or 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
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.
The AK protocol often relies on sentinel value (e.g. null or -1) to indicate that a field was not provided. Usually, these sentinels are turned into
java.util.Optionalthat is empty when the field is equal to the sentinel. Until now, we were doing this transformation while mapping the Struct to internal Request or Response classes. With the generated protocol, we would like to get rid of these internal classes and also avoid spending time to construct them.This PR is an attempt to support
java.util.Optionalin the auto-generated classes. A field can be marked asoptionalthat indicates to the generator that its type must be wrapped in anOptional.When an optional is written, its internal value is used or its default if the optional is undefined. When an option is read, the value read is used or it defaults to an empty optional if the default value is read.
I did a deep integration by changing all the places where values are written or read to do the above conversions. I just wrote it as a proof of concept to discuss this further. The code may be simplified.
An alternative to this would be to only provide getters and setters which convert the internal value to an Optional and vice versa. That would limit the scope of the change. The downside would be that every time the getters or the setters are called, it requires to do the conversion.
Committer Checklist (excluded from commit message)