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

Q: specify other name for "py/object" key? #365

Open
lsloan opened this issue Oct 20, 2021 · 1 comment
Open

Q: specify other name for "py/object" key? #365

lsloan opened this issue Oct 20, 2021 · 1 comment
Labels
enhancement not-a-bug Something that seems like a bug but is intended behavior

Comments

@lsloan
Copy link

lsloan commented Oct 20, 2021

Is there a way to configure jsonpickle or extend/override its code to use a different name for the "py/object" key? Specifically, I'd like to name the key "type" instead.

I suspect specifying a different pickler class would be a possible approach. I'd also like to change how the value of the key is formatted, too. For example, using the sample code on the front page of the documentation, rather than using the value "__main__.Thing", I'd like it to use simply "Thing".

@Theelx
Copy link
Contributor

Theelx commented Dec 17, 2021

At the moment, there is not a way to make it use a different key. The issue with that would be that jsonpickle matches the value's type based on the name of the key.
If you want to make a custom pickler/unpickler class, I believe you could do it by somehow modifying this line:

OBJECT = 'py/object'

But I believe you'd need to re-encode the objects after you change that if you want to be able to deserialize them again.

@Theelx Theelx added enhancement not-a-bug Something that seems like a bug but is intended behavior labels Jan 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement not-a-bug Something that seems like a bug but is intended behavior
Projects
None yet
Development

No branches or pull requests

2 participants