protected function deserialize($data, string $class)
    {
        // @todo Is this extractor required?
        $dataServiceExtractor = new DataServiceExtractor();
        $dataServiceExtractor->setClass($this->dataService->getClass());
        $dataServiceExtractor->setCustomFields($this->dataService->getCustomFields());

        // The serializer treats the $xmlns as it's own separate property, and
        // there is no way to access it from within the extractor. We can't
        // alter $context in the CJsonEncoder as it is not passed by reference.
        // @todo This feels like a bit of a hack.
        $decoded = \GuzzleHttp\json_decode($data, true);
        if (isset($decoded['$xmlns'])) {
            $dataServiceExtractor->setNamespaceMapping($decoded['$xmlns']);
        }

        $p = new PropertyInfoExtractor([], [$dataServiceExtractor], [], []);
        $cached = new PropertyInfoCacheExtractor($p, $this->cacheItemPool);

        $object = $this->getObjectSerializer($cached)->deserialize($data, $class, 'json');

        // Adds any missing custom field classes. A given object may not
        // contain any set fields in a given custom field namespace. In that
        // case, the serializer will never create a field class. This is fine
        // until calling code wants to check to see if a given field exists.
        // By ensuring we add in any missing custom field definitions, we
        // ensure a valid object is returned instead of null.
        if ($object instanceof ObjectInterface) {
            $customFields = $object->getCustomFields();
            $remaining = array_diff_key($this->dataService->getCustomFields(), $customFields);

            /** @var string $namespace */
            /** @var DiscoveredCustomField $field */
            foreach ($remaining as $namespace => $field) {
                $namespaceClass = $field->getClass();
                $customFields[$namespace] = new $namespaceClass();
            }

            $object->setCustomFields($customFields);
        }

        if ($object instanceof JsonInterface) {
            $object->setJson($data);
        }

        return $object;
    }
protected function deserialize($data, string $class)
    {
        // @todo Is this extractor required?
        $dataServiceExtractor = new DataServiceExtractor();
        $dataServiceExtractor->setClass($this->dataService->getClass());
        $dataServiceExtractor->setCustomFields($this->dataService->getCustomFields());

        // The serializer treats the $xmlns as it's own separate property, and
        // there is no way to access it from within the extractor. We can't
        // alter $context in the CJsonEncoder as it is not passed by reference.
        // @todo This feels like a bit of a hack.
        $decoded = \GuzzleHttp\json_decode($data, true);
        if (isset($decoded['$xmlns'])) {
            $dataServiceExtractor->setNamespaceMapping($decoded['$xmlns']);
        }

        $p = new PropertyInfoExtractor([], [$dataServiceExtractor], [], []);
        $cached = new PropertyInfoCacheExtractor($p, $this->cacheItemPool);

        $object = $this->getObjectSerializer($cached)->deserialize($data, $class, 'json');

        // Adds any missing custom field classes. A given object may not
        // contain any set fields in a given custom field namespace. In that
        // case, the serializer will never create a field class. This is fine
        // until calling code wants to check to see if a given field exists.
        // By ensuring we add in any missing custom field definitions, we
        // ensure a valid object is returned instead of null.
        if ($object instanceof ObjectInterface) {
            $customFields = $object->getCustomFields();
            $remaining = array_diff_key($this->dataService->getCustomFields(), $customFields);

            /** @var string $namespace */
            /** @var DiscoveredCustomField $field */
            foreach ($remaining as $namespace => $field) {
                $namespaceClass = $field->getClass();
                $customFields[$namespace] = new $namespaceClass();
            }

            $object->setCustomFields($customFields);
        }

        if ($object instanceof JsonInterface) {
            $object->setJson($data);
        }

        return $object;
    }
protected function deserialize ( $ data , string $ class ) { // @todo Is this extractor required? $ dataServiceExtractor = new DataServiceExtractor ( ) ; $ dataServiceExtractor -> setClass ( $ this -> dataService -> getClass ( ) ) ; $ dataServiceExtractor -> setCustomFields ( $ this -> dataService -> getCustomFields ( ) ) ; // The serializer treats the $xmlns as it's own separate property, and // there is no way to access it from within the extractor. We can't // alter $context in the CJsonEncoder as it is not passed by reference. // @todo This feels like a bit of a hack. $ decoded = \ GuzzleHttp \ json_decode ( $ data , true ) ; if ( isset ( $ decoded [ '$xmlns' ] ) ) { $ dataServiceExtractor -> setNamespaceMapping ( $ decoded [ '$xmlns' ] ) ; } $ p = new PropertyInfoExtractor ( [ ] , [ $ dataServiceExtractor ] , [ ] , [ ] ) ; $ cached = new PropertyInfoCacheExtractor ( $ p , $ this -> cacheItemPool ) ; $ object = $ this -> getObjectSerializer ( $ cached ) -> deserialize ( $ data , $ class , 'json' ) ; // Adds any missing custom field classes. A given object may not // contain any set fields in a given custom field namespace. In that // case, the serializer will never create a field class. This is fine // until calling code wants to check to see if a given field exists. // By ensuring we add in any missing custom field definitions, we // ensure a valid object is returned instead of null. if ( $ object instanceof ObjectInterface ) { $ customFields = $ object -> getCustomFields ( ) ; $ remaining = array_diff_key ( $ this -> dataService -> getCustomFields ( ) , $ customFields ) ; /** @var string $namespace */ /** @var DiscoveredCustomField $field */ foreach ( $ remaining as $ namespace => $ field ) { $ namespaceClass = $ field -> getClass ( ) ; $ customFields [ $ namespace ] = new $ namespaceClass ( ) ; } $ object -> setCustomFields ( $ customFields ) ; } if ( $ object instanceof JsonInterface ) { $ object -> setJson ( $ data ) ; } return $ object ; }
Deserialize a JSON string into a class.

@todo Inject the serializer in the constructor?

@param string $data  The JSON string to deserialize.
@param string $class The full class name to create.

@return mixed An object matching the $class parameter.
Deserialize a JSON string into a class .