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?
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 ofJMS\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 theUnitOfWork
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.