public function serialize($value)
    {
        $this->reset();
        $serializedData = $this->serializeData($value);
        $encoded = json_encode($serializedData, $this->calculateEncodeOptions());
        if ($encoded === false || json_last_error() != JSON_ERROR_NONE) {
            if (json_last_error() != JSON_ERROR_UTF8) {
                throw new JsonSerializerException('Invalid data to encode to JSON. Error: ' . json_last_error());
            }

            $serializedData = $this->encodeNonUtf8ToUtf8($serializedData);
            $encoded = json_encode($serializedData, $this->calculateEncodeOptions());

            if ($encoded === false || json_last_error() != JSON_ERROR_NONE) {
                throw new JsonSerializerException('Invalid data to encode to JSON. Error: ' . json_last_error());
            }
        }
        return $this->processEncodedValue($encoded);
    }
public function serialize($value)
    {
        $this->reset();
        $serializedData = $this->serializeData($value);
        $encoded = json_encode($serializedData, $this->calculateEncodeOptions());
        if ($encoded === false || json_last_error() != JSON_ERROR_NONE) {
            if (json_last_error() != JSON_ERROR_UTF8) {
                throw new JsonSerializerException('Invalid data to encode to JSON. Error: ' . json_last_error());
            }

            $serializedData = $this->encodeNonUtf8ToUtf8($serializedData);
            $encoded = json_encode($serializedData, $this->calculateEncodeOptions());

            if ($encoded === false || json_last_error() != JSON_ERROR_NONE) {
                throw new JsonSerializerException('Invalid data to encode to JSON. Error: ' . json_last_error());
            }
        }
        return $this->processEncodedValue($encoded);
    }
public function serialize ( $ value ) { $ this -> reset ( ) ; $ serializedData = $ this -> serializeData ( $ value ) ; $ encoded = json_encode ( $ serializedData , $ this -> calculateEncodeOptions ( ) ) ; if ( $ encoded === false || json_last_error ( ) != JSON_ERROR_NONE ) { if ( json_last_error ( ) != JSON_ERROR_UTF8 ) { throw new JsonSerializerException ( 'Invalid data to encode to JSON. Error: ' . json_last_error ( ) ) ; } $ serializedData = $ this -> encodeNonUtf8ToUtf8 ( $ serializedData ) ; $ encoded = json_encode ( $ serializedData , $ this -> calculateEncodeOptions ( ) ) ; if ( $ encoded === false || json_last_error ( ) != JSON_ERROR_NONE ) { throw new JsonSerializerException ( 'Invalid data to encode to JSON. Error: ' . json_last_error ( ) ) ; } } return $ this -> processEncodedValue ( $ encoded ) ; }
Serialize the value in JSON

@param  mixed $value
@return string JSON encoded
@throws JsonSerializerException
Serialize the value in JSON