protected function extractAttributes(array $data, EntityMetadata $metadata)
    {
        $flattened = [];
        if (!isset($data['attributes']) || !is_array($data['attributes'])) {
            return $data['attributes'] = [];
        }

        $keyMap = array_flip(array_keys($data['attributes']));
        foreach ($metadata->getProperties() as $key => $propMeta) {
            if (!isset($keyMap[$key])) {
                continue;
            }
            if (true === $metadata->hasAttribute($key) || true === $metadata->hasEmbed($key)) {
                $flattened[$key] = $data['attributes'][$key];
            }
        }
        return $flattened;
    }