Skip to content

Unable to have a flattened object use same property name as the object above #113

Description

@Sam-Mear

See the json

{
      "field": "ur.entity_type",
      "operator": "=",
      "value": "product"
}

and the PHP classes:

class Filter
{
    public function __construct(
        #[\Crell\Serde\Attributes\Field(flatten: true)]
        public ValidatedString $field,
        public string $operator,// todo: move to enum
        public string $value,
    ) {
    }
}

class ValidatedString
{
    protected const ALLOWED_PATTERN = '/^[a-z.]+$/';

    public function __construct(
        public string $value
    ) {}

    #[\Crell\Serde\Attributes\PostLoad]
    protected function validate(): void
    {
        if (!preg_match(self::ALLOWED_PATTERN, $this->value)) {
            throw new \InvalidArgumentException(
                sprintf(
                    'Invalid text "%s". Only lowercase letters (a-z) and dots (.) are allowed.',
                    $this->value
                )
            );
        }
    }
}

Due to both these objects having the property of value It fails around here src/PropertyHandler/ObjectImporter.php::103 where you're passing in $remaining, and later on you get the error "Warning: Undefined array key "value" in /var/www/html/vendor/crell/serde/src/PropertyHandler/ObjectImporter.php on line 70"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions