I want to use the symfony serializer and found this in the services.xml of this bundle
<service id="serializer" alias="jms_serializer.serializer" /><!-- Here for BC, may be disabled in the config -->
I saw, that you can disable it by setting enable_short_alias: false which I did in my config.yml, however, now, every service which needs the "serializer" gets this error
Unable to replace alias "fos_elastica.serializer" with actual definition "serializer". and You have requested a non-existent service "serializer".
When I debug through my code and am in the ContainerBuilder::getDefinition method, inspecting the $this->definitions is showing me, that there is no serializer registered. I deleted the cache of course, but nothin ghappened. Any idea what this could be? This is the serializer.xml of the FrameworkBundle of Symfony
<service id="serializer" class="Symfony\Component\Serializer\Serializer">
<argument type="collection" />
<argument type="collection" />
</service>
If it helps: I'm using the version 1.2.1
http://jmsyst.com/bundles/JMSSerializerBundle/master/configuration#extension-reference
put on your config.yml
jms_serializer:
enable_short_alias: false
@goetas: Please read the third paragraph of my issue. I already said
I saw, that you can disable it by setting enable_short_alias: false which I did in my config.yml, however, now, every service which needs the "serializer" gets this error
The exception is thrown BECAUSE of this setting.
did you check https://github.com/FriendsOfSymfony/FOSElasticaBundle/blob/master/Resources/doc/serializer.md#a-install-and-declare-the-serializer ?
Yes, I did. If I understood the Configuration correctly, this
->arrayNode('serializer')
->treatNullLike(array())
->children()
->scalarNode('callback_class')->defaultValue('FOS\ElasticaBundle\Serializer\Callback')->end()
->scalarNode('serializer')->defaultValue('serializer')->end()
->end()
->end()
means, that if it's null I have an empty array, correct? Which means that it defaults to serializer, correct? But since serializer was jms_serializer before it worked, and now I have to change the config in
fos_elastica:
serializer: ~
to
fos_elastica:
serializer: jms_serializer.serializer
right?
Update: If I change that to
fos_elastica:
serializer:
serializer: jms_serializer.serializer
it works again (so far). Thanks for your help, just misconfigured it apparently.
Sorry @goetas , have to interrupt again. When I now call the service serializer, I get the following message
You have requested a non-existent service "serializer". Did you mean one of these: "fos_elastica.index.app.product.serializer.callback", "fos_rest.serializer.exception_wrapper_serialize_handler", "jms_serializer", "jms_serializer.array_collection_handler", "jms_serializer.constraint_violation_handler", "jms_serializer.datetime_handler", "jms_serializer.deserialization_context_factory", "jms_serializer.doctrine_proxy_subscriber", "jms_serializer.expression_evaluator", "jms_serializer.form_error_handler", "jms_serializer.handler_registry", "jms_serializer.json_deserialization_visitor", "jms_serializer.json_serialization_visitor", "jms_serializer.metadata_driver", "jms_serializer.metadata_factory", "jms_serializer.naming_strategy", "jms_serializer.object_constructor", "jms_serializer.php_collection_handler", "jms_serializer.serialization_context_factory", "jms_serializer.stopwatch_subscriber", "jms_serializer.templating.helper.serializer", "jms_serializer.unserialize_object_constructor", "jms_serializer.xml_deserialization_visitor", "jms_serializer.xml_serialization_visitor", "jms_serializer.yaml_serialization_visitor", "mapudo_core.serializer.builder_factory", "symfony.component.serializer.mapping.factory.class_metadata_factory"
It seems like removing the alias also removes the service? But that can't be, right?
Which serializer do you need?
jms_serializer (just serializer is not available and is reserved for symfony).enable_short_alias: false, then the instance name is jms_serializer (just serializer is not available).enable_short_alias: true, then the instance name is jms_serializer or serializer, and both will refer to the jms serializer (this setup is not recommended since it conflicts with the symfony serializer).I want to use both. We use the JMS-Serializer for our API but I know wanted to normalize an object (use the basic serializer functionality), because the JMSSerializer in our version doesn't have the method normalize.
Isn't it possible to use both at the same time?
as said:
the symfony serializer, looks not enabled or installed
you have to figure out why the symfony serializer is not available....
regarding the jms serializer:
enable_short_alias: false and refer everywhere to the jms serializer using jms_serializer@goetas
you have to figure out why the symfony serializer is not available....
Because I made a mistake. I forgot to enable it in the framework
framework:
# ...
serializer: { enable_annotations: true }
I replaced all occurences of serializer with jms_serializer and configured the enable_short_alias, but no result.
framework:
#esi: ~
serializer: { enabled: true }
jms_serializer:
enable_short_alias: false
fos_elastica:
serializer:
serializer: jms_serializer.serializer // same error with jms_serializer
This is how it looks now, and this is the error
A circular reference has been detected (configured limit: 1).
I'm currently digging to find out where this comes from.
This looked more like a configuration problem, however. I just resetted my changes and have redone them. Now it works. I will report back if I find anything.
@goetas Yeah, I think I found the problem and seems like it has to do with the FOSRestBundle, not with this one.
if ($container->has('jms_serializer.serializer')) {
$container->setAlias('fos_rest.serializer', 'jms_serializer.serializer');
} else {
$container->removeDefinition('fos_rest.serializer.exception_wrapper_serialize_handler');
}
if ($container->has('serializer')) {
$container->setAlias('fos_rest.serializer', 'serializer');
} else {
$container->removeDefinition('fos_rest.serializer.exception_wrapper_normalizer');
}
That's the problem. The FOSRestBundle uses the serializer instead of the jms_serializer just because both are defined
http://symfony.com/doc/current/bundles/FOSRestBundle/1-setting_up_the_bundle.html#c-enable-a-serializer
This documentation sounds like this is how it should be done, and there is no way around that unless I define fos_rest.serializer myself.
Yeah, I think I found the problem and seems like it has to do with the FOSRestBundle, not with this one.
I doubt
the symfony serializer, looks not enabled or installed
you have to figure out why the symfony serializer is not available....
Maybe you forgot this:
The serializer service is not available by default. To turn it on, activate it in your configuration
http://symfony.com/doc/current/serializer.html#activating-the-serializer
@goetas Yeah, look at tthis post here: https://github.com/schmittjoh/JMSSerializerBundle/issues/583#issuecomment-307379924
I forgot it.
Almost everything works now. The JMS Serializer is doing what it should do, no errors at all, BUT here's the BUT. When I access the serializer via $this->get('serializer'); it still returns the jms_serializer. Last problem to fix prorbably, then I'm good to go.
Ok, final answer. It seems to work now :D. Don't know what I changed between now and the previous comments, but I'm good to go now, finally> Thanks for your time.
Most helpful comment
Update: If I change that to
it works again (so far). Thanks for your help, just misconfigured it apparently.