mindplay-dk/jsonfreeze

Not working with base classes

Opened this issue · 1 comments

I try to use the latest version of jsonfreeze, but I have no luck with a simple object graph:

abstract class AbstractSessionData implements SessionData {

        private $version;
        private $customerId;
        private $sessionId;
        private $user;
        private $status;

        // some implementations of getters and setters defined by interface SessionData
}

class HeartbeatSession extends AbstractSessionData {

    private $timeLeft;
    private $logoutUri;
    private $userId;

    //...
}

I use your library to serialize an object of class HeartbeatSession:

public static function writeSessionData(string $key, SessionData $dao): bool {

    $serializer = new JsonSerializer();
    var_dump($dao);
    $str = $serializer->serialize($dao);
    var_dump($str);
    return (file_put_contents($key, $serializer->serialize($dao)) !== false);
}

The first var_dump writes the whole object graph inclusive the values from AbstractSessionData, but the var_dump of the serializer results only shows the values from the subclass HeartbeatSession. Is this an error?

The test includes an example with inherited, private properties:

jsonfreeze/test/test.php

Lines 23 to 24 in b7c234f

eq($json, '{"#type":"OrderLineEx","color":"blue","data":"two","item":"shoe","amount":2,"options":[],"OrderLine#data":"one"}');
// ^^^^^^^^^^^^ own private ^^^^^^^^^^^^^^^^^^^^^^ inherited private

So that shouldn't be an issue.

I can't spot anything wrong with your code.

Let me know if you figure it out?