schmittjoh / JMSSerializerBundle

Easily serialize, and deserialize data of any complexity (supports XML, JSON, YAML)
http://jmsyst.com/bundles/JMSSerializerBundle
MIT License
1.8k stars 311 forks source link

overriding jms_serializer.object_constructor is unreliable #442

Open vith opened 9 years ago

vith commented 9 years ago

Finally figured out why the instructions in the docs weren't working for me: it depends on the order that bundles are loaded in AppKernel.php.

Specifically, JMS\SerializerBundle\JMSSerializerBundle must be loaded before the bundle containing the service override. Otherwise, JMSSerializerBundle overrides your own service alias definition instead of the other way around.

Curiously, jms_serializer.object_constructor is always an instance of JMS\Serializer\Construction\DoctrineObjectConstructor even if I don't try to override it, but it's not until I tested whether my deserialized object was persisted via the UnitOfWork that I could tell if my override was successful.

I'm thinking this should either be done with a global config.yml option or something in DeserializationContext, or both?

This fork of symfony-standard-edition demonstrates the problem. Just swap these two lines and see the difference at the very end of the / route's output.

frak commented 7 years ago

This is clearly not an issue with JMS Serializer, and actually just demonstrates how Symfony works