Skip to content

[Serializer] AbstractObjectNormalizer: Allow to disable type enforcement #23404

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

Merged
merged 1 commit into from
Jul 12, 2017
Merged

[Serializer] AbstractObjectNormalizer: Allow to disable type enforcement #23404

merged 1 commit into from
Jul 12, 2017

Conversation

ogizanagi
Copy link
Contributor

@ogizanagi ogizanagi commented Jul 5, 2017

Q A
Branch? 3.4
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes (failure unrelated)
Fixed tickets N/A
License MIT
Doc PR N/A

This allows to denormalize simple DTOs with public properties using the property-info component and the ObjectNormalizer. The raised exception is not really useful in such cases, as it cannot be easily handled gracefully to build a proper violation response (too generic and no real hint on the complete attribute path for instance).
Instead, I use the validator component to validate my DTOs and the properties' types, get a proper violation list, and build a response from it.

I wasn't really inspired for the DISABLE_TYPE_ENFORCEMENT name.

@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Jul 10, 2017
@@ -289,6 +290,10 @@ private function validateAndDenormalize($currentClass, $attribute, $data, $forma
}
}

if (isset($context[self::DISABLE_TYPE_ENFORCEMENT]) && $context[self::DISABLE_TYPE_ENFORCEMENT]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!empty(...)

@nicolas-grekas
Copy link
Member

Thank you @ogizanagi.

@nicolas-grekas nicolas-grekas merged commit 959ac2a into symfony:3.4 Jul 12, 2017
nicolas-grekas added a commit that referenced this pull request Jul 12, 2017
…e type enforcement (ogizanagi)

This PR was merged into the 3.4 branch.

Discussion
----------

[Serializer] AbstractObjectNormalizer: Allow to disable type enforcement

| Q             | A
| ------------- | ---
| Branch?       | 3.4 <!-- see comment below -->
| Bug fix?      | no
| New feature?  | yes <!-- don't forget updating src/**/CHANGELOG.md files -->
| BC breaks?    | no
| Deprecations? | no <!-- don't forget updating UPGRADE-*.md files -->
| Tests pass?   | yes (failure unrelated)
| Fixed tickets | N/A <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | N/A

This allows to denormalize simple DTOs with public properties using the property-info component and the `ObjectNormalizer`. The raised exception is not really useful in such cases, as it cannot be easily handled gracefully to build a proper violation response (too generic and no real hint on the complete attribute path for instance).
Instead, I use the validator component to validate my DTOs and the properties' types, get a proper violation list, and build a response from it.

I wasn't really inspired for the `DISABLE_TYPE_ENFORCEMENT` name.

Commits
-------

959ac2a [Serializer] AbstractObjectNormalizer: Allow to disable type enforcement
@ogizanagi ogizanagi deleted the feature/serializer/disable_type_enforcement branch July 12, 2017 14:42
This was referenced Oct 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants