How to disable the Doctrine shipment in the deserialization?

Asked

Viewed 18 times

0

I use the JMSSerializerBundle (jms/serializer-Bundle) to make data serialization and deserialization, recently updated the project now when deserialize the object is already loaded by Doctrine, however I do not want the objects that I load by the method mentioned below, have this behavior, how to disable?

I wrote the function below to retrieve and convert json in the request body into objects from the specific classes of my project, but while trying to retrieve and parse where my intention was only to create the proper instances of the elements and popular only with the information received from the json, instead apparently he tries to recover the instance using Lazy loading from Doctrine and already leaves associated with Proxies_GC_<class>, lazyProperties and etc.. , if I send for example a class without the id property I get messages like "The Identifier id is Missing for a query of ..."

public function getObject(Request $request, $class, $useShowGroup = false, $type = null)
{
    $format = 'json';
    $context = null;
    if ($useShowGroup == true) {
        $context = DeserializationContext::create();
        $groups = ['Show', 'Default'];
        $context->setGroups($groups);
    }
    $mBodyData = array();
    $body = $request->getContent();
    if (!empty($body) && $format == 'json') {
        $mBodyData = json_decode($body, true);
    }

    $data = array_merge(
        $request->request->all(),
        empty($mBodyData) ? array() : $mBodyData,
        !empty($type) ? array('t_type' => $type) : array()
    );
    $mData = json_encode((object)array_filter($data));
    //$mData = json_encode($data);
    return $this->serializer->deserialize($mData, $class, $format, $context);
}
  • Is your question very confusing? Did you create this method? could it be clearer Doctrine charged as?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.