-
-
Notifications
You must be signed in to change notification settings - Fork 78
Refactor: Promote SimpleDTOProjection to official NameBasedProjection feature with collection support #1460
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
Conversation
|
All tests have passed successfully I’m always learning a lot from you, @velo |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1460 +/- ##
========================================
Coverage ? 0.00%
========================================
Files ? 838
Lines ? 31795
Branches ? 3622
========================================
Hits ? 0
Misses ? 31795
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
|
a bit rough to review what changed can you bring back the original names or reduce the delta a bit so git can match the files and I can look at what changed, not a whole file |
Thanks for the feedback. I reverted the file/class names back to the original so git can match the file, and I tried to keep the diff as small as possible. Because the behavior changed a bit (we now fallback when constructor parameter names are missing), I updated some method names to better reflect what they do now. If that’s too much for this round, I can rename them back as well. After this is reviewed, would it be okay to rename the class to Thanks again! |
|
All good, I think all that is missing is code format and done |
Head branch was pushed to by a user without write access
Thank you so much for approving the changes! After the approval, I reverted the class name back to Would you mind helping me adjust it to the correct format? |
👋 Description
Hello QueryDSL team, it’s been a while!
I'm Mouon (munhyunjune), the original contributor who previously implemented the
SimpleDTOProjectionfeature.At my company, we have been using this version in our internal QueryDSL-based project.
However, we found some limitations in real-world usage:
To address these issues, I have refactored and finalized this feature as
NameBasedProjection, making it an official, production-ready component.🧩 Key Changes
Renamed
SimpleDTOProjection→NameBasedProjectionto clarify its purpose and align with QueryDSL’s naming style.Added support for multiple entities in the projection constructor (
EntityPathBase<?>... entities).Improved constructor matching logic to handle parameter names and fallback gracefully to field order when compiled without
-parameters.Enhanced error handling for missing field/parameter mappings.
Added detailed Javadoc comments, especially for the
binder()method, explaining:Updated tests (
NameBasedProjectionTest) to verify multiple-entity and collection field handling.🧠 Feature Details
NameBasedProjectionenables automatic mapping between DTOs and entities by matching field names, eliminating the need for explicit field-by-field projection definitions.This reduces boilerplate and improves readability, especially when working with large DTOs.
Example Comparison
Before:
After:
The class automatically binds entity fields to matching DTO constructor parameters (by name),
with fallback support for unnamed parameters (
arg0,arg1, …) based on field order.🧪 Testing
Projections.fields()andNameBasedProjection.🙏 Feedback Welcome
If there are any shortcomings or stylistic issues, I would be more than happy to receive feedback.
My goal is to have this feature officially merged so that we can use it in our production environment.
I believe this enhancement can help many developers reduce redundant projection code and make DTO binding much easier.
Thank you again for maintaining this great project and taking the time to review this PR! 🙏
Please let me know if I should make any adjustments.