private function getParentObjectInlining($object, SerializationContext $context) { $metadataStack = $context->getMetadataStack(); $visitingStack = $context->getVisitingStack(); $parentObject = null; if (count($visitingStack) > 0) { $parentObject = $visitingStack[0]; } if ($parentObject === $object && count($visitingStack) > 1) { $parentObject = $visitingStack[1]; // $object is inlined inside $parentObject } if ($metadataStack->count() > 0 && isset($metadataStack[0]->inline) && $metadataStack[0]->inline && $this->serializerMetadataFactory->getMetadataForClass(get_class($parentObject)) === $metadataStack[1]) { return $parentObject; } return null; }