-
-
Notifications
You must be signed in to change notification settings - Fork 587
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
Prevent deserialisation with missing required field #1090
Comments
This probably could be achieved in the client of this libaray by setting a default But I suspect that would be less performant than building the check in to |
Validation of the deserialized object is a rather complex topic, better to use libs as |
Late to the party, but I disagree with this Slippery slope argument. The reason for Required/Optional requirement inside library is the fact that there is a developer expectation that if I deserialize a DTO I either get a valid DTO or error and no DTO -- here valid means that the encapsulation is not broken, which is by quite broken by leaving random fields uninitialized :/ |
Hi! |
I have tried
and it still gets uninitialized when missing. |
When deserialising an object, it would be useful to know that all required fields are present,
and the caller hasn't forgotten to set them. I think it might make sense to introduce new
annotations
@Serializer\Required
and@Serializer\Optional
, with a config option to set which one is assumed by default. Optional would be the same as current behaviour.Related to #821
Steps required to reproduce the problem
Run the following script:
Expected Result
deserialize
should throw some exception if $someProperty is annotated as required, or the serializer is configured to treat properties as required by defaultActual Result
NULL
The text was updated successfully, but these errors were encountered: