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

Reconstruct object from custom serialization #346

Open
MarkNahabedian opened this issue Jul 20, 2022 · 1 comment
Open

Reconstruct object from custom serialization #346

MarkNahabedian opened this issue Jul 20, 2022 · 1 comment

Comments

@MarkNahabedian
Copy link

JSON.jl allows for customizing how instances of a Julia type are serialized to JSON by defining a show_json method on a custom subtype of CommonSerialization.

There doesn't seem to be a way to specialize parse to reconstruct an analog of the original object from that serialization though.

For example, Regex isn't serializable using CommonSerialization because it contains a Ptr. A custom serialization could represent the Regex as a combination of a tag and a string. I don't see a way to customize parse to make a Regex from that string when it recognizes that tag. One would need to walk the entire data structure looking for and replacing these custom serializations.

This would only work when the JSON is being parsed using the same custom Serialization, but that is better than nothing.

Python supports thus functionality by passing 'hook' functions to load and loads.

@KristofferC
Copy link
Member

I think https:/quinnj/JSON3.jl provides this.

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