Skip to content
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

Notice when trying to de-serizlize incorrect value type #880

Closed
smilesrg opened this issue Feb 28, 2018 · 5 comments
Closed

Notice when trying to de-serizlize incorrect value type #880

smilesrg opened this issue Feb 28, 2018 · 5 comments
Assignees
Labels

Comments

@smilesrg
Copy link

Notice: Array to string conversion in /var/www/html/protected/vendor/jms/serializer/src/JMS/Serializer/GenericDeserializationVisitor.php on line 61

It happens when trying to de-serialize a model, one of the property type is defined as a string in configuration, but actual value is an array. Maybe in this case any exceptions have to be catched and throwed some JMS\Serializer\Exception\Exception?

@goetas
Copy link
Collaborator

goetas commented Mar 1, 2018

Not sure about it... your underlying data looks to be an array, but you declared it as a string.... so a php error is what to expect.

@goetas goetas closed this as completed Mar 1, 2018
@smilesrg
Copy link
Author

smilesrg commented Mar 5, 2018

@goetas I think it shoul be catched and converted to exception to let developer know of incorrect configuration or incorrect value. For example, if incorrect value received via POST request, exception definately should be thrown, not just notice.

@goetas goetas self-assigned this Mar 5, 2018
@gitnik
Copy link

gitnik commented Dec 5, 2019

In our project we convert notices to exceptions because they often hide code smells in PHP and we thus want execution to stop. With this behaviour, we have no way to gracefully handle invalid POST data in our API. Would you be willing to accept a pull request here?

@goetas
Copy link
Collaborator

goetas commented Dec 6, 2019

Would you be willing to accept a pull request here?

Generally speaking, yes!
What would be the proposed solution? typecheck each property being visited?

@smilesrg
Copy link
Author

smilesrg commented Dec 13, 2019

What would be the proposed solution? typecheck each property being visited?

I think yes, it's what needed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants