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

Serializer and stateful dependencies should be unshared #608

Closed
wants to merge 1 commit into from
Closed

Serializer and stateful dependencies should be unshared #608

wants to merge 1 commit into from

Conversation

lstrojny
Copy link

@lstrojny lstrojny commented Oct 10, 2017

An invocation of Serializer::serialize() leads to "Can't pop from an empty datastructure" in SplStack if the serializer invocation leads to another serializer invocation on the same service down the road. In my case that happened when the serializer used doctrine to load an entity which logged a message on dev but there was logging functionality that uses the serializer.

This is the reproduction case:

class Foo
{
    /** @Serializer\Exclude() */
    public $serializer;
    /** @Serializer\Accessor(getter="get") */
    private $property;
    public function get() { return $this->serializer->serialize('foo', 'json'); }
}

$serializer = $container->get('jms_serializer');
$obj = new Foo();
$obj->serializer = $container->get('jms_serializer');

$serializer->serialize($obj, 'json');

To fix this, jms_serializer and its stateful dependencies may not be shared. This PR marks the following services as not shared:

  • jms_serializer
  • jms_serializer.json_serialization_visitor
  • jms_serializer.xml_serialization_visitor
  • jms_serializer.yaml_serialization_visitor
  • jms_serializer.json_deserialization_visitor
  • jms_serializer.xml_deserialization_visitor

@goetas
Copy link
Collaborator

goetas commented Oct 16, 2017

hmm, this problems is the same of schmittjoh/serializer#341 but with a different solution.

I'm starting to see it as a common problem.

The solution you used might work only in some cases when used with symfony, but not in other situations.
The solution in #341 works better but is more complex.

Another approach I was thinking about, were "visitor factories" to inject into the serializer class.
That approach will generate new visitors on each serialization call...

@goetas
Copy link
Collaborator

goetas commented May 4, 2018

This is solved in serializer 2.0 and will be released soon.

@goetas goetas closed this May 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants