-
-
Notifications
You must be signed in to change notification settings - Fork 586
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
introduce requireAllRequiredProperties context #1554
introduce requireAllRequiredProperties context #1554
Conversation
@idbentley is this still needed given the state of the union discriminator feature recently merged? |
e334a2b
to
d8c5ee5
Compare
009bbdf
to
4bad485
Compare
Hi @goetas yes, I still need these changes. They are only incidentally related to unions. This pull request introduces a As a simple example:
Since the
With this PR in place, and the appropriate Context provided:
The serializer will throw an |
This feature is crossing the delicate ground between serialization and validation. In the past I had similar proposals and I always tried to keep them outside of the serializer because is validation is a complex thing (see just how big is the symfony validator comoponent). because of it I would really like to keep this outside of the serializer |
I agree that increasing the complexity of validation in the serializer is a slippery slope, but I would like to argue that this is actually more of a type check consideration, which the serializer already does. If I try to deserialize:
With the wrong data type:
The system will throw an exception: RuntimeException: This is much the same - the expected data type is Non nullable, and the visited type is While it would be possible for me to add a validator to the json data, I would be doing that solely for this |
@goetas I'm gonna take another shot at convincing you that this is worth keeping in the seializer.
I hope you'll reconsider :) |
@goetas I wonder if you'd had a chance to consider this? |
Hi @goetas Have you had a chance to read my posts? |
I would really like to keep the graph visitor as simple as possible (and to keep validation outside of the serializer), so I'm going to close this pull request (I owe you a clear action, without gigling around it). |
Long time ago i worked on #1005 to handle explicitly null... then i worked also on other stuff that never made it to github (like a |
This statement is very confusing to me. The graph visitor already does type validation. The current behaviour of the deserializer is inconsistent and it's handling of null values is a type checking bug. The serializer type checks of every piece of data it deserializes except null values. Deserializing a null value into an I put the bug fix behind a configuration flag because I didn't want to introduce a regression, but this PR is a bug fix. It's a shame that you close it without any justification beyond "too complicated". |
This pull request introduces a new
DeserializationContext
attribute that allows you to specify that you'd like deserialization to fail if the JSON is missing required properties.