DataStack example



    protected function validateMapping(
        JsonField $field,
        array $data,
        WriteParameterBag $parameters
    ): array {
        if (\array_key_exists('_class', $data)) {
            unset($data['_class']);
        }

        $stack = new DataStack($data);
        $existence = EntityExistence::createEmpty();
        $fieldPath = $parameters->getPath() . '/' . $field->getPropertyName();

        $propertyKeys = array_map(fn (Field $field) => $field->getPropertyName()$field->getPropertyMapping());

        // If a mapping is defined, you should not send properties that are undefined.         // Sending undefined fields will throw an UnexpectedFieldException         $keyDiff = array_diff(array_keys($data)$propertyKeys);
        if (\count($keyDiff)) {
            foreach ($keyDiff as $fieldName) {
                $parameters->getContext()->getExceptions()->add(
                    


        return new KeyValuePair($field->getPropertyName(), null, true);
    }

    /** * @param array<string, mixed> $rawData */
    private function createDataStack(EntityExistence $existence, EntityDefinition $definition, WriteParameterBag $parameters, array $rawData): DataStack
    {
        if ($existence->exists()) {
            return new DataStack($rawData);
        }

        $defaults = $existence->isChild() ? $definition->getChildDefaults() : $definition->getDefaults();

        if ($defaults === []) {
            return new DataStack($rawData);
        }

        $toBeNormalized = $rawData;
        foreach ($defaults as $key => $value) {
            if (\array_key_exists($key$rawData)) {
                
Home | Imprint | This part of the site doesn't use cookies.