Add the ability for the DtoFactory to accept an instance implementing#13220
Closed
metlos wants to merge 1 commit intoeclipse-che:masterfrom
Closed
Add the ability for the DtoFactory to accept an instance implementing#13220metlos wants to merge 1 commit intoeclipse-che:masterfrom
metlos wants to merge 1 commit intoeclipse-che:masterfrom
Conversation
a super type of the DTO interface (from which the DTO inherits its getters) and produce a DTO instance from it. This should basically eliminate the need for the "asDto()" methods sprinkled around the codebase and cut on the boilerplate significantly. Signed-off-by: Lukas Krejci <lkrejci@redhat.com>
Contributor
|
Can one of the admins verify this patch? |
Contributor
|
Issues go stale after Mark the issue as fresh with If this issue is safe to close now please do so. Moderators: Add |
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.
What does this PR do?
Our DTO generator contains copy constructor and our
DtoFactoryis able to clone a DTO instance into a new deeply-copied one.But when it comes to converting our JPA entities into the DTOs we use the very verbose
DtoConverters sprinkled around the codebase, hand-written and amounting to hundreds of lines of tedious, error-prone code each.This PR tries to eliminate the need for the
DtoConverters by adding the ability to (partially) initialize the DTO instances also from instances implementing some common superinterface with the DTO (typically, our JPA entities implement a common interface with the DTOs) and adding a newDtoFactory.cloneFrom()method that tries to initialize a new DTO instance from an object by checking whether such conversion is possible at runtime.What we gain by this is several thousands of lines of code potentially removed, if we replace our
DtoConverters with this.What we loose is a little bit of type safety where the check whether a conversion from a certain object to a DTO instance becomes manual and errors only pop up at runtime. On the other hand, our current approach is also error prone because we cannot enforce initialization of newly added properties in all the converters (this is a manual step now, which is automagically handled by this PR).
What issues does this PR fix or reference?
none