-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add fluent problem properties #132
base: main
Are you sure you want to change the base?
Conversation
@Test | ||
void fluentProperties() { | ||
InputValidationProblem problem = new MyInputValidationProblem() | ||
.detail("detail message") |
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.
If we don't override the fluent setters in InputValidationProblem, this chaining wouldn't work.
You would need to reverse the order to
InputValidationProblem problem = new MyInputValidationProblem()
.issues(InputValidationIssues.requiredInput(InEnum.QUERY, "test"))
.detail("detail message");
The self-referencing generics trick we used in https://github.com/belgif/rest-problem-java/pull/101/files cannot be applied here, because an exception class cannot be generic.
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.
I've played around with the implementation but wasn't able to find an alternative approach. Even looked at the manifold compiler plugin which Pieter often mentions but even its crazy change features don't seem to often anything we can use here.
Simply a limitation of the language.
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.
I tried out another approach with interfaces and default methods to reduce the boilerplate.
One drawback is that an explicit implements Fluent*Problem<SELF>
is required on all concrete problem classes that wish to have these fluent properties. Whereas in the previous approach the fluent properties would automatically be inherited from the super class (but with the "wrong" return type, requiring to override to allow proper method chaining).
What do you think @belgif/rest-problem-java?
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.
If it does the trick, it's good for me. Adding more children with new properties to the hierarchy will make it more complex but I don't think we are going into that direction.
Quality Gate failedFailed conditions |
Quality Gate passedIssues Measures |
No description provided.