Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working with base classes #9

Open
witchi opened this issue Feb 12, 2021 · 1 comment
Open

Not working with base classes #9

witchi opened this issue Feb 12, 2021 · 1 comment

Comments

@witchi
Copy link

witchi commented Feb 12, 2021

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?

@mindplay-dk
Copy link
Owner

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants