After updating JMSSerializerBundle
+ JMSSerializer
(4.2.0 / 3.22.0 --> 5.3.1 / 3.28.0) in my Symfony 6.3, deserialized object are now automatically added to the Doctrine EntityManager (= become managed objects).
Upon investigation I found out, that this is because now during deserialization the DoctrineObjectConstructor
is used instead of the UnserializeObjectConstructor
.
What is the correct way to configure the Bundle to use UnserializeObjectConstructor
again?
Disabling doctrine as object constructor in the config seems to solve the problem:
jms_serializer:
object_constructors:
doctrine:
enabled: false
However, I am not sure if this has some side effects. Since the docs do not state any BC I do not understand why this config change should be necessary. Is this a missing info in the docs, is there something wrong in my config? Is this the correct / intended way of keeping JMS from adding deserialized objects from being added to the EntityManager?
Details:
JSON objects can be send to the project which are then deserialized into real objects. However, these object are (and should be) "flat", which means that references to other object are only saved as IDs, that as actual references. For example the a deserialized Employee
objects holds in its department
property only string ID and not a Department
instance. Thus these deserialized objects should not be managed since would lead to error during persist / flush operations.
Before the updates this was no problem, since the objects where created using UnserializeObjectConstructor
and not added to the EntityManager. However, after the update the DoctrineObjectConstructor
is called instead and the objects are now managed.
Since I have made no other changed, this seems to be a BC in JMSSerializerBundle
although there are no mentioned in the docs. I found an issue at Github which might be related, but this should only effect older version. The changed described there are already included in versions I used before the update (4.2.0 / 3.22.0).
How can I correct this?