getPropertyMapping example

KeyValuePair $data,
        WriteParameterBag $parameters
    ): \Generator {
        if (!$field instanceof JsonField) {
            throw DataAbstractionLayerException::invalidSerializerField(JsonField::class$field);
        }

        $this->validateIfNeeded($field$existence$data$parameters);

        $value = $data->getValue() ?? $field->getDefault();

        if ($value !== null && !empty($field->getPropertyMapping())) {
            $value = $this->validateMapping($field$value$parameters);
        }

        if ($value !== null) {
            $value = Json::encode($value);
        }

        yield $field->getStorageName() => $value;
    }

    public function decode(Field $field, mixed $value): mixed
    {

            $jsonPath = implode('.', $jsonPathParts);
        }

        $jsonValueExpr = sprintf(
            'JSON_EXTRACT(`%s`.`%s`, %s)',
            $root,
            $field->getStorageName(),
            (string) $this->connection->quote('$' . $jsonPath)
        );

        $embeddedField = $this->getField($jsonPath$field->getPropertyMapping());
        $accessor = $this->getFieldAccessor($jsonValueExpr$embeddedField);

        /* * Values extracted from json have distinct json types, that are different from normal value types. * We need to convert json nulls into sql nulls. * * For example: `JSON_EXTRACT('{"foo":null}', '$.foo') IS NOT NULL` */
        return sprintf('IF(JSON_TYPE(%s) != "NULL", %s, NULL)', $jsonValueExpr$accessor);
    }

    
'customerPriceCount' => TypeMappingInterface::MAPPING_LONG_FIELD,
                'fallbackPriceCount' => TypeMappingInterface::MAPPING_LONG_FIELD,

                // Dates                 'formattedCreatedAt' => TypeMappingInterface::MAPPING_DATE_FIELD,
                'formattedUpdatedAt' => TypeMappingInterface::MAPPING_DATE_FIELD,
                'formattedReleaseDate' => TypeMappingInterface::MAPPING_DATE_FIELD,

                // Nested structs                 'manufacturer' => $this->getManufacturerMapping($shop),
                'priceGroup' => $this->getPriceGroupMapping(),
                'properties' => $this->getPropertyMapping($shop),
                'esd' => $this->getEsdMapping(),
                'tax' => $this->getTaxMapping(),
                'unit' => $this->getUnitMapping(),

                'attributes' => $this->getAttributeMapping(),
                'configuration' => $this->getVariantOptionsMapping($shop),

                'voteAverage' => $this->getVoteAverageMapping(),
                'manualSorting' => $this->getManualMapping(),
            ],
        ];

        
'items' => $this->getPropertyAssocsByField($jsonField instanceof ListField ? $jsonField->getFieldType() : null),
            ]);
        } else {
            $definition = new Property([
                'type' => 'object',
                'property' => $jsonField->getPropertyName(),
            ]);
        }

        $required = [];

        if (!empty($jsonField->getPropertyMapping())) {
            $definition->properties = [];
        }

        foreach ($jsonField->getPropertyMapping() as $field) {
            if ($field instanceof JsonField) {
                $definition->properties[] = $this->resolveJsonField($field);

                continue;
            }

            if ($field->is(Required::class)) {
                

    private function createJsonObjectType(EntityDefinition $definition, Field $field, array $flags): array
    {
        $nested = [];
        if ($field instanceof JsonField) {
            foreach ($field->getPropertyMapping() as $nestedField) {
                $nested[$nestedField->getPropertyName()] = $this->parseField($definition$nestedField);
            }
        }

        return [
            'type' => 'json_object',
            'properties' => $nested,
            'flags' => $flags,
        ];
    }
}
Home | Imprint | This part of the site doesn't use cookies.