public function marshall(ServletSessionInterface $servletSession)
    {

        // create the stdClass (that can easy be transformed into an JSON object)
        $sessionData = array();

        // copy the values to the stdClass
        $sessionData[StandardSessionMarshaller::ID] = $servletSession->getId();
        $sessionData[StandardSessionMarshaller::NAME] = $servletSession->getName();
        $sessionData[StandardSessionMarshaller::LIFETIME] = $servletSession->getLifetime();
        $sessionData[StandardSessionMarshaller::MAXIMUM_AGE] = $servletSession->getMaximumAge();
        $sessionData[StandardSessionMarshaller::DOMAIN] = $servletSession->getDomain();
        $sessionData[StandardSessionMarshaller::PATH] = $servletSession->getPath();
        $sessionData[StandardSessionMarshaller::SECURE] = $servletSession->isSecure();
        $sessionData[StandardSessionMarshaller::HTTP_ONLY] = $servletSession->isHttpOnly();
        $sessionData[StandardSessionMarshaller::LAST_ACTIVITY_TIMESTAMP] = $servletSession->getLastActivityTimestamp();

        // initialize the array for the session data
        $sessionData[StandardSessionMarshaller::DATA] = array();

        // append the session data
        foreach ($servletSession->data as $key => $value) {
            $sessionData[StandardSessionMarshaller::DATA][$key] = serialize($value);
        }

        // JSON encode the session instance
        $encodedSession = json_encode($sessionData);

        // query whether or not the session data has been decoded successfully
        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new SessionDataNotReadableException(json_last_error_msg());
        }

        // return the JSON encoded session data
        return $encodedSession;
    }
public function marshall(ServletSessionInterface $servletSession)
    {

        // create the stdClass (that can easy be transformed into an JSON object)
        $sessionData = array();

        // copy the values to the stdClass
        $sessionData[StandardSessionMarshaller::ID] = $servletSession->getId();
        $sessionData[StandardSessionMarshaller::NAME] = $servletSession->getName();
        $sessionData[StandardSessionMarshaller::LIFETIME] = $servletSession->getLifetime();
        $sessionData[StandardSessionMarshaller::MAXIMUM_AGE] = $servletSession->getMaximumAge();
        $sessionData[StandardSessionMarshaller::DOMAIN] = $servletSession->getDomain();
        $sessionData[StandardSessionMarshaller::PATH] = $servletSession->getPath();
        $sessionData[StandardSessionMarshaller::SECURE] = $servletSession->isSecure();
        $sessionData[StandardSessionMarshaller::HTTP_ONLY] = $servletSession->isHttpOnly();
        $sessionData[StandardSessionMarshaller::LAST_ACTIVITY_TIMESTAMP] = $servletSession->getLastActivityTimestamp();

        // initialize the array for the session data
        $sessionData[StandardSessionMarshaller::DATA] = array();

        // append the session data
        foreach ($servletSession->data as $key => $value) {
            $sessionData[StandardSessionMarshaller::DATA][$key] = serialize($value);
        }

        // JSON encode the session instance
        $encodedSession = json_encode($sessionData);

        // query whether or not the session data has been decoded successfully
        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new SessionDataNotReadableException(json_last_error_msg());
        }

        // return the JSON encoded session data
        return $encodedSession;
    }
public function marshall ( ServletSessionInterface $ servletSession ) { // create the stdClass (that can easy be transformed into an JSON object) $ sessionData = array ( ) ; // copy the values to the stdClass $ sessionData [ StandardSessionMarshaller :: ID ] = $ servletSession -> getId ( ) ; $ sessionData [ StandardSessionMarshaller :: NAME ] = $ servletSession -> getName ( ) ; $ sessionData [ StandardSessionMarshaller :: LIFETIME ] = $ servletSession -> getLifetime ( ) ; $ sessionData [ StandardSessionMarshaller :: MAXIMUM_AGE ] = $ servletSession -> getMaximumAge ( ) ; $ sessionData [ StandardSessionMarshaller :: DOMAIN ] = $ servletSession -> getDomain ( ) ; $ sessionData [ StandardSessionMarshaller :: PATH ] = $ servletSession -> getPath ( ) ; $ sessionData [ StandardSessionMarshaller :: SECURE ] = $ servletSession -> isSecure ( ) ; $ sessionData [ StandardSessionMarshaller :: HTTP_ONLY ] = $ servletSession -> isHttpOnly ( ) ; $ sessionData [ StandardSessionMarshaller :: LAST_ACTIVITY_TIMESTAMP ] = $ servletSession -> getLastActivityTimestamp ( ) ; // initialize the array for the session data $ sessionData [ StandardSessionMarshaller :: DATA ] = array ( ) ; // append the session data foreach ( $ servletSession -> data as $ key => $ value ) { $ sessionData [ StandardSessionMarshaller :: DATA ] [ $ key ] = serialize ( $ value ) ; } // JSON encode the session instance $ encodedSession = json_encode ( $ sessionData ) ; // query whether or not the session data has been decoded successfully if ( json_last_error ( ) !== JSON_ERROR_NONE ) { throw new SessionDataNotReadableException ( json_last_error_msg ( ) ) ; } // return the JSON encoded session data return $ encodedSession ; }
Transforms the passed session instance into a JSON encoded string. If the data contains
objects, each of them will be serialized before store them to the persistence layer.

@param \AppserverIo\Psr\Servlet\ServletSessionInterface $servletSession The session to be transformed

@return string The JSON encoded session representation
@throws \AppserverIo\Appserver\ServletEngine\DataNotSerializableException Is thrown, if the session can't be encoded
@see \AppserverIo\Appserver\ServletEngine\SessionMarshallerInterface::marshall()
Transforms the passed session instance into a JSON encoded string . If the data contains objects each of them will be serialized before store them to the persistence layer .