Set response body if is not string json_encode

@param mixed $data
@return $this
192592
public function setResponseBody($data)
    {
        if (!is_string($data)) {
            $data = json_encode($data, \JSON_PRETTY_PRINT);
        }
        $this->response->getBody()->write($data);
        return $this;
    }
1285897
public static function createFromJsonResponse($data)
    {
        $data = json_decode($data, true);

        $stacks = array_map(function ($stack) {
            return Stack::createFromDecodedJsonResponse($stack);
        }, $data['items']);

        return new self($stacks);
    }
678078
public function setData($data)
    {
        if ( ! is_string($data)) {
            throw new UnexpectedValueException('Expected string with file content');
        }

        $this->content = $data;

        $this->size = strlen($data);

        return $this;
    }
344542
public function setData($data)
    {
        foreach ($data as $key => $dtoData) {
            $this->data[$key] = new RuneDto($dtoData);
        }
    
        return $this;
    }
228475
public function setResponse($response)
    {
        $this->response = (null !== $response) ? (string) $response : null;
        return $this;
    }
1037061
public function setContent($content = null)
    {
        if (null !== $content && !is_string($content)) {
            throw new ResponseException('Response content must be a string.');
        }

        $this->content = (string) $content;

        return $this;
    }
711738
public function setRestContent($data)
    {
        $serializer = $this->getSerializer();

        if (isset($data)) {
            $this->setContent($serializer->serialize($data, $this->format));
        }

        return $this;
    }
734962
protected function wrapBody($data = '')
    {
        // HTTP
        if (false !== strpos($this->scheme, 'http')) {
            // Body
            $body = '';
            if (!empty($data)) {
                if (!in_array($this->method, ['GET', 'HEAD', 'OPTIONS'])) {
                    $body = Json::encode((array) $data);
                    $this->setHeader('Content-Length', strlen($body));
                    $this->setHeader('Content-Type', 'application/json');
                } else {
                    if (is_array($data)) {
                        $data = http_build_query($data);
                    }
                    $this->path .= (false === strpos($this->path, '?') ? '?' : '&') . $data;
                }
            }

            //Cookie
            $cookies = '';
            foreach ($this->cookies as $cookie) {
                $cookies .= $cookie->asString();
            }

            //Header
            $ua = static::USER_AGENT;
            $version = static::HTTP_VERSION;
            $header = "{$this->method} {$this->path} HTTP/{$version}\r\n";
            foreach ($this->headers as $key => $value) {
                $header .= "$key: " . (is_array($value) ? implode(',', $value) : $value) . "\r\n";
            }
            if (!empty($cookies)) {
                $header .= "Cookie: {$cookies}\r\n";
            }
            $header .= "Accept: application/json\r\n";
            $header .= "User-Agent: {$ua}\r\n";
            $header .= "\r\n";

            $data = $header . $body;
        } else {
            $body = [
                'method'  => $this->method,
                'path'    => $this->path,
                'headers' => $this->headers,
            ];
            if (!empty($data)) {
                $body['body'] = (array) $data;
            }
            $data = Json::encode($body);
        }

        return $data;
    }
374553
public function setBody($body)
    {
        $body = json_encode($body);

        if ($error = json_last_error()) {
            throw new \ErrorException($error);
        }

        curl_setopt($this->curlHandler, CURLOPT_POSTFIELDS, $body);

        return $this;
    }
577258
public function withXMLBody($data, SerializationContext $context = null)
    {
        if (is_string($data)) {
            $xml = $data;
        } else {
            $xml = SerializerBuilder::create()->build()->serialize($data, 'xml', $context);
        }
        $this->addHeader('Content-Type', 'text/xml; charset=utf-8');
        $this->withBody($xml);

        return $this;
    }
359564
protected function setData($data = [])
    {
        $defaults = [
            'content'  => '',
            'data'     => null,
        ];

        $this->data = array_merge($defaults, $data);

        return $this;
    }
786531
protected function setParsedBody($data)
    {
        if (! is_null($data) && ! is_array($data) && ! is_object($data)) {
            throw new InvalidArgumentException(sprintf(
                'Invalid parsed body provided; must be an null, or array, '
                . 'or object, "%s" provided.',
                gettype($data)
            ));
        }
        $this->parsedBody = $data;

        return $this;
    }
1302892
public function setRawJsonBody(array $data)
    {
        $this->addHeader('Content-Type', 'application/json');
        $this->setBody(Stream::factory(json_encode($data)));
        return $this;
    }
329287
public function set($data)
    {
        $this->error = [];
        $result = null;
        switch ($this->format) {
            case 'nvp':
                parse_str($data, $this->data);
                $result = !empty($this->data);
                break;

            case 'json':
            default:
                $this->data = empty($data) ? [] : (json_decode($data, true) ?: []);
                $result = json_last_error() == JSON_ERROR_NONE;
                if (empty ($result)) {
                    $this->error = [
                        'error' => json_last_error(),
                        'msg'   => json_last_error_msg(),
                    ];
                }
                break;
        }

        return $result;
    }
32341
public function configure(array $data) 
	{
		$this->checkData($data);
		$body = new MimeMessage();
		$body->addPart($this->getPart($data));
		$this->setBody($body);

		$this->addTo($data['to']);
		//$this->addReplyTo($data['from']);
		$this->setSubject(utf8_decode($this->subject));
		
		return $this;
	}
1166199
public function set_data( $data ) {
		if ( isset( $data[ $this->slug ] ) ) {
			if ( is_string( $data[ $this->slug ] ) ) {
				$is_json = json_decode( $data[ $this->slug ], ARRAY_A );
				if ( ! empty( $is_json ) ) {
					$data[ $this->slug ] = $is_json;
				} else {
					$data[ $this->slug ] = str_replace( '{{@root', '{{json @root', $data[ $this->slug ] );
				}
			}
			$this->data[ $this->id() ][ $this->slug ] = apply_filters( 'uix_' . $this->slug . '_sanitize_' . $this->type, $data[ $this->slug ], $this );
		}

	}
594328
public function sendData($data)
    {
        $httpResponse = $this->httpClient->post(
            $this->getEndpoint(),
            ['Content-Type' => 'text/xml; charset=utf-8'],
            $this->xmlSerialize($data)
        )->send();

        return $this->response = $this->newResponse( $httpResponse->xml() );
    }