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

Encoded Object with Tuple[float, float, float] results in no values stored #322

Open
MochaMoth opened this issue Sep 29, 2020 · 0 comments

Comments

@MochaMoth
Copy link

Essentially, I have an object Point with member position: Tuple[float, float, float]. When pickled, the json just has the data type set to builtins.Vector with none of the values stored. To work around, I had to break out the position member to x, y, and z floats. This has the same result with and without explicit typing.

Point.py

from typing import Tuple

class Point:
    position: Tuple[float, float, float] = (0, 0, 0)

    def __init__(self, position: Tuple[float, float, float]):
        self.position = position

    def __str__(self) -> str:
        return f"({self.position[0]:.2f}, {self.position[1]:.2f}, {self.position[2]:.2f})"

SomewhereElse.py

import jsonpickle
from ..DataTypes import Point

def Save(point: Point):
        jsonPoint = jsonpickle.encode(point)
        Debug.Log(point)
        Debug.Log(jsonPoint)

Output

[DEBUG   ] - (0.88, 0.88, 1.25)
[DEBUG   ] - {
    "py/object": "DataTypes.Point.Point",
    "position": {
        "py/object": "builtins.Vector"
    }
}
davvid added a commit to davvid/jsonpickle that referenced this issue Feb 8, 2021
Reapply the changes to references to dictionaries.

Closes jsonpickle#351
Related-to: jsonpickle#255 jsonpickle#322
Signed-off-by: David Aguilar <davvid@gmail.com>
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

1 participant