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

Immutable js data is deserialized with errors #19

Closed
jsmonkey opened this issue Apr 20, 2018 · 3 comments
Closed

Immutable js data is deserialized with errors #19

jsmonkey opened this issue Apr 20, 2018 · 3 comments

Comments

@jsmonkey
Copy link
Contributor

Hi guys,

I'm using redux-persist which uses remotedev-serialize which uses your package for (de)serialization of the Immutable js app state.

When several properties in the object tree have the same values then jsan tries to reuse first entry of the value using references to it in other places.

For example:

obj = {
    prop1: 'sample value',
    prop2:  {
        prop3: 'sample value'
    }
}

after serialization will be

{ "prop1": "sample value", "prop2":  { "prop3": "$.prop1" }}

But with Immutable js during the serialization remotedev-serialize with help of jsan converts immutable js structures into it's own representation and serializes it.

So the references for the same values are built over the converted structure instead of the original Immutable js structures.

And during the deserialization jsan first transforms its own representation to the original Immutable js structure and only after that trying to resolve references for the same values but fails and always returns undefined cuz such references for its own representation can't be resolved on the original Immutable js structure.

jsan/lib/index.js

Lines 43 to 50 in a37187a

if (arguments.length === 1) {
parsed = JSON.parse(text);
} else {
parsed = JSON.parse(text, reviver);
}
if (needsRetrocycle) {
parsed = cycle.retrocycle(parsed);
}

@jsmonkey
Copy link
Contributor Author

I've created PR with fix.

@kolodny
Copy link
Owner

kolodny commented Apr 29, 2018

This should be closed via #7 right?

@jsmonkey
Copy link
Contributor Author

jsmonkey commented May 2, 2018

It was resolved with this pr

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