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

Remove zend json from data object #10306

Merged

Conversation

@dmanners
Copy link
Contributor

commented Jul 24, 2017

Description

The DataObject class has a method toJson that uses Zend_Json. Since this at EOF we should replace the usage. Unfortunately in this case that is not so "simple" after some discussion with @okorshenko it was decided to create a new static class for this single case. This should not be used in other places but for this case it is "ok".

Fixed Issues (if relevant)

  1. #9236: Upgrade ZF components. Zend_Json

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)
dmanners added 2 commits Jul 18, 2017
Replay the static call to Zend_Json with a static call to Magento Jso…
…nConverter.

 - This is only in place for this one use case and should not be used for other times with converting json

@okorshenko okorshenko self-assigned this Jul 24, 2017

@okorshenko okorshenko added this to the July 2017 milestone Jul 24, 2017

@okorshenko okorshenko added the develop label Jul 24, 2017

@ihor-sviziev

This comment has been minimized.

Copy link
Contributor

commented Jul 24, 2017

@dmanners Why do we need new object with static method? We could add to constructor optional parameter (with fallback to object manager)

@dmanners

This comment has been minimized.

Copy link
Contributor Author

commented Jul 24, 2017

@ihor-sviziev I am more than happy to find another option but unfortunately going the route of adding an optional dependency causes big breaks in the test suite. I am not sure exactly how the object manager changes in the test suite so there could be an option to mock the fallback during the test suite.

@orlangur

This comment has been minimized.

Copy link
Contributor

commented Jul 24, 2017

Why do we need to add new behavior with @throws \InvalidArgumentException instead of just calling json_encode?

What do you think about deprecating toJson method also to decrease amount of DataObject class responsibilities?

@okorshenko

This comment has been minimized.

Copy link
Contributor

commented Jul 24, 2017

Hi @orlangur removing the method from DataObject interface will be BiC that we would like to avoid. The standard approach for adding new dependencies to DataObject does not work well due to modularity. So we suggested the way that @dmanners implemented.

@dmanners

This comment has been minimized.

Copy link
Contributor Author

commented Jul 24, 2017

@orlangur normally I would like to keep away from the direct calls to json_encode but in the case of this class with the combination of the deprecation of the toJson I think I could live with myself. This class itself needs a lot of love or at least the usages of this class need some love and care so highlighting that is not a bad thing in my books. What do you think @okorshenko

@magento-team magento-team merged commit 7ab108a into magento:develop Jul 24, 2017

3 checks passed

codacy/pr Good work! A positive pull request.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
licence/cla Contributor License Agreement is signed.
Details
@orlangur

This comment has been minimized.

Copy link
Contributor

commented Jul 24, 2017

@okorshenko I did not say a word regarding method removal, just deprecation. As to me static class introduction with comment to use it in only one place is much uglier than simply using json_encode in this place (the only difference compared to serializer https://github.com/magento/magento2/blob/develop/lib/internal/Magento/Framework/Serialize/Serializer/Json.php#L24 is not throwing an exception which corresponds to old method behavior).

@korostii

This comment has been minimized.

Copy link

commented Jul 25, 2017

Hi @okorshenko
As @orlangur says, there's nothing wrong with both keeping the method present and avoiding new dependencies.
However, what's the point of using \Magento\Framework\Serialize\JsonConverter instead?

After all, the new @throws declaration a BiC change by itself.
How is it any better than using json_encode directly?

@dmanners dmanners deleted the dmanners:remove-zend-json-from-data-object branch Jul 26, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.