public function deserialize($data, $type, $format, DeserializationContext $context = null) { if (!$this->deserializationVisitors->containsKey($format)) { throw new UnsupportedFormatException(sprintf('The format "%s" is not supported for deserialization.', $format)); } if (null === $context) { $context = new DeserializationContext(); } $context->initialize($format, $visitor = $this->deserializationVisitors->get($format)->get(), $this->navigator, $this->factory); $visitor->setNavigator($this->navigator); $navigatorResult = $this->navigator->accept($visitor->prepare($data), $this->typeParser->parse($type), $context); // This is a special case if the root is handled by a callback on the object iself. if (null === ($visitorResult = $visitor->getResult()) && null !== $navigatorResult) { return $navigatorResult; } return $visitorResult; }