Skip to content

JSON type: Cannot persist due to failing validation #383

@Pittiplatsch

Description

@Pittiplatsch

With #168 JSON support was introduced.

However, JSON fields cannot be persisted with Doctrine_Core::VALIDATE_TYPES enabled.

There is no way to pass \Doctrine_Validator::isValidType() for $type === 'json':

       if ($var instanceof Doctrine_Expression) {
            return true;
        } elseif ($var === null) {
            return true;
        } elseif (is_object($var)) {

// This applies to JSON backed values with \stdClass values

            return $type == 'object';
        } elseif (is_array($var)) {

// This MIGHT (according to JSON condition below) apply to JSON backed values

            return $type == 'array';
        }

        switch ($type) {
// [...]
            case 'array':
                return is_array($var);
            case 'object':
                return is_object($var);
            case 'json':

// Even IF we ever reach here, e.g. with already json_encode()'d string,
// condition fails as the only two possible options already yielded <false> in the beginning.

                return is_object($var) || is_array($var);
// [...]
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions