-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
[REQ][spring] Required properties of a model should be made mandatory in constructor #9789
Comments
Would not javax.validation take care of this req? I am not sure, I am just asking. However, your request makes sense. Lombok should not be used as it is adding yet another dependency to the generated stuff, and it has it's own... drawbacks. |
* Add constructor with required parameter for spring Fix #9789 * [Java][Spring] constructor with required args --------- Co-authored-by: Oleh Kurpiak <[email protected]>
There is no way to enforce "is required". This request is pointless imho.
It might add a way of adding more convinience using that POJO by having an additional constructor - but thats all, nothing else. To really enforce "is required" you would need to:
but then you get a POJO which can't be used with mapping or serialization/deserialization frameworks.... so stop attempting something you can't reach |
Perhaps I am missing a constraint but what challenges/blockers would have to be solved to be able to add null checks on setters? (The setters could then be re-used in the constructor or builder). |
Yeah this probably could be done. On the other hand the default constructor could never be removed I guess. That said there will always be a chance of ending up with null values for required-props. |
Problem
The constructors of the generated models with the spring generator have no builders, empty constructors. The fact that a property is required is only in an annotation that I do not think has any other effect than informing the reader.
Describe the solution you'd like
IMHO there should be a constructor that would have all the required properties in it and no constructor without it. This way you'd enforce setting those up. Otherwise what stops you from sending responses from the server without required properties?
Describe alternatives you've considered
using lombok to create builders and constructors would be nice in general.
Is there some way generated server stub ensures adhering to the contract in the question of required attribute?
The text was updated successfully, but these errors were encountered: