This function takes an array of elements provided by a decoded response from the server and uses
it to create a DTO representing the resource being deserialized.


@param $json_data array
@param $type string The class type to be created
@return array
963590
public static function createFromJSON($json_data, $type = null)
    {
        $className = explode('\\', $type);
        $className = lcfirst(end($className));

        $allFields = parent::createFromJSON($json_data, $type);
        $compositeFields = CompositeDTOMapper::compositeFields(get_class($allFields));
        foreach ($compositeFields as $key) {
            if (isset($allFields->$key)) {
                $allFields->$key = self::synthesizeSubresource($key, $json_data[$key], $className);
            }
        }
        return $allFields;

    }
1311731
public function jsonSerialize(): array
    {
        $instruction = ['type' => $this->type];

        if ($this->type !== self::TYPE_NOOP) {
            $instruction = array_merge($instruction, [
                'name' => $this->name,
                'catched' => $this->shouldCatchErrors,
            ]);

            if ($this->type !== self::TYPE_GET) {
                $instruction['value'] = $this->value;
            }

            if ($this->resource !== null) {
                $instruction['resource'] = $this->resource;
            }
        }

        return $instruction;
    }
359470
public function jsonSerialize()
    {
        $ret = new StdClass;
        foreach ($this->map as $key => $value) {
            $ret->$key = (bool)($this->source & $value);
        }
        return $ret;
    }
988780
public function jsonSerialize(): stdClass
    {
        $object = (object)object_get_properties($this, $this instanceof DynamicEntity);

        /** @var Event\ToJson $event */
        $event = $this->dispatchEvent(new Event\ToJson($this, $object));
        $data = i\type_check($event->getPayload(), stdClass::class, new UnexpectedValueException());

        return $data;
    }
452490
function jsonSerialize(): \stdClass {
    return (object) [
      'sourceFile' => $this->getSourceFile(),
      'branches' => ($branches = $this->getBranches()) ? $branches->jsonSerialize() : null,
      'functions' => ($functions = $this->getFunctions()) ? $functions->jsonSerialize() : null,
      'lines' => ($lines = $this->getLines()) ? $lines->jsonSerialize() : null
    ];
  }
956900
public function jsonSerialize() {
        $ret = new \stdClass();
        $ret->name = $this->name;

        if(count($this->values) > 0) {
            $values = array();
            $values['values'] = $this->values;
            $ret->values = $values;
        }

        $ret->nullable = $this->nullable;

        return $ret;
    }
1074703
protected function _json_decode($data, $need_array = false)
  {
    if (!(defined('JSON_C_VERSION') && PHP_INT_SIZE > 4)) {
      return json_decode($data, $need_array, 512, JSON_BIGINT_AS_STRING);
    }
    return json_decode($data, $need_array);
  }
489054
public static final function jsonDecode($data, array $options = null): array
    {
        $encoder = new JsonEncoder($options);

        return [$encoder->decode($data), $encoder->hasError()
            ? new EncoderException('JSON Error: '. $encoder->getError()) : null];
    }
565810
public static function getList($data)
    {
        // Return Null if Null
        if ($data === null) {
            return null;
        }

        if (is_a($data, get_class(new \stdClass()))) {
            //This means, root element is object

            $accessibleProperties = get_object_vars($data);

            if (count($accessibleProperties) == 1
                && (isset($accessibleProperties['error']) || isset($accessibleProperties['errors']))
            ) {
                // Object is only an error {"error":"message"} or {"errors":["error1":"message1"]}
                return new Error(JsonConverter::encode($data));
            } else {
                return new static(JsonConverter::encode($data));
            }
        }

        $list = array();

        if (is_array($data)) {
            $data = JsonConverter::encode($data);
        }

        if (JsonValidator::validate($data)) {
            // It is valid JSON
            $decoded = JsonConverter::decode($data);
            if ($decoded === null) {
                return $list;
            }
            if (is_array($decoded)) {
                foreach ($decoded as $k => $v) {
                    $list[] = self::getList($v);
                }
            }
            if (is_a($decoded, get_class(new \stdClass()))) {
                //This means, root element is object
                $list[] = new static(JsonConverter::encode($decoded));
            }
        }

        return $list;
    }
480539
protected function __create(array $data, $index, $type, $id = null, array $parameters = []) {
        $parameters+=["api" => "create"];
        $api = strtolower($parameters["api"]) == "index" ? "index" : "create";
        unset($parameters["api"]);
        $result = $this->client->$api([
            'index' => $index,
            'type' => $type,
            'body' => $data] + ($id ? ['id' => $id] : []) + $parameters);
        if (array_key_exists('_shards', $result) && array_key_exists('failed', $result['_shards']) && $result['_shards']['failed'] > 0) {
            throw new Exception('Failed to create the document. Serialized results: ' + json_encode($result));
        } else {
            $result = $this->__find($result['_index'], $result['_type'], $result['_id']);
        }
        return $result;
    }
117811
public function templates($type)
    {
        $data      = [];
        $extension = $this->repository->findOrFail($type);
        foreach ($extension->param('templates') as $template) {
            $data[] = ['key' => $template['path'], 'value' => $template['description']];
        }

        return response()->json([
            'template' => $data[0]['key'],
            'selected' => $type,
            'data'     => $data,
        ], 200);
    }
764708
public function deserializePersonalValue(string $type, string $json): SerializablePersonalDataValue {
        $values = json_decode($json);

        $personalKey = PersonalKey::deserialize($values->personalKey);
        $dataKey     = PersonalDataKey::deserialize($values->dataKey);
        
        return $type::deserialize($this->dataStore->retrieveData($personalKey, $dataKey)->toString());
    }
1142630
function jsonSerialize(): \stdClass {
    return (object) [
      'testName' => $this->getTestName(),
      'records' => array_map(function(Record $item) {
        return $item->jsonSerialize();
      }, $this->getRecords()->getArrayCopy())
    ];
  }
622676
public function getObjectsKeys($type = 'all')
	{
		$keys = null;

		if ($type == 'all')
		{
			$function = 'array_merge';
		}
		elseif ($type == 'common')
		{
			$function = 'array_intersect_key';
		}
		else
		{
			throw new \InvalidArgumentException("Unknown selection type: $type");
		}

		foreach ($this->objects as $object)
		{
			if (version_compare(PHP_VERSION, '5.4.0', '<'))
			{
				$objectVars = json_decode(json_encode($object->jsonSerialize()), true);
			}
			else
			{
				$objectVars = json_decode(json_encode($object), true);
			}

			$keys = ($keys === null) ? $objectVars : $function($keys, $objectVars);
		}

		return array_keys($keys);
	}
597064
public static function parseErrors($json_string)
    {
        $error_obj = json_decode($json_string);
        $errors = [];
        if (!empty($error_obj->errors)) {
            foreach ($error_obj->errors as $error) {
                $errors[] = new self($error->code, $error->path, $error->description);
            }
        } elseif (!empty($error_obj->error)) {
            $errors[] = new self('', '', $error_obj->error);
        }

        return $errors;
    }
114344
public static function createFromDecodedJsonResponse($data)
    {
        $areas = [];
        foreach ($data as $name => $area) {
            $areas[$name] = [];
            foreach ($area as $class => $data) {
                $metaClass = DynamicMetadataHelper::getDynamicMetadataClassName($class);
                /* @var DynamicMetadataInterface $metaClass */
                $areas[$name][] = $metaClass::createFromDecodedJsonResponse($data);
            }
        }

        return new self($areas);
    }
392256
public function jsonSerialize() {
        $ret = new \stdClass();
        $requiredTargetAttributes = array();
        $requiredTargetAttributes['requiredTargetAttributes'] = $this->requiredTargetAttributes;
        $ret->requiredTargetAttributes = $requiredTargetAttributes;
        $ret->targetAttributes = $this->targetAttributes;

        return $ret;
    }