instantiateObject example



        return $data;
    }

    /** * @return object */
    protected function instantiateObject(array &$data, string $class, array &$context, \ReflectionClass $reflectionClass, array|bool $allowedAttributes, string $format = null)
    {
        if ($class !== $mappedClass = $this->getMappedClass($data$class$context)) {
            return $this->instantiateObject($data$mappedClass$contextnew \ReflectionClass($mappedClass)$allowedAttributes$format);
        }

        return parent::instantiateObject($data$class$context$reflectionClass$allowedAttributes$format);
    }

    /** * Gets and caches attributes for the given object, format and context. * * @return string[] */
    protected function getAttributes(object $object, ?string $format, array $context): array
    {
$this->assertSame('baz', $normalizedData->baz);
    }

    public function testInstantiateObjectDenormalizer()
    {
        $data = ['foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'];
        $class = Dummy::class;
        $context = [];

        $normalizer = new AbstractObjectNormalizerDummy();

        $this->assertInstanceOf(Dummy::class$normalizer->instantiateObject($data$class$contextnew \ReflectionClass($class)[]));
    }

    public function testDenormalizeWithExtraAttribute()
    {
        $this->expectException(ExtraAttributesException::class);
        $this->expectExceptionMessage('Extra attributes are not allowed ("fooFoo" is unknown).');
        $factory = new ClassMetadataFactory(new AnnotationLoader());
        $normalizer = new AbstractObjectNormalizerDummy($factory);
        $normalizer->denormalize(
            ['fooFoo' => 'foo'],
            Dummy::class,
            


        return $data;
    }

    /** * @return object */
    protected function instantiateObject(array &$data, string $class, array &$context, \ReflectionClass $reflectionClass, array|bool $allowedAttributes, string $format = null)
    {
        if ($class !== $mappedClass = $this->getMappedClass($data$class$context)) {
            return $this->instantiateObject($data$mappedClass$contextnew \ReflectionClass($mappedClass)$allowedAttributes$format);
        }

        return parent::instantiateObject($data$class$context$reflectionClass$allowedAttributes$format);
    }

    /** * Gets and caches attributes for the given object, format and context. * * @return string[] */
    protected function getAttributes(object $object, ?string $format, array $context): array
    {
Home | Imprint | This part of the site doesn't use cookies.