question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow to pass object to fromJSON

See original GitHub issue

Use case scenario:

Server renders:

<script>
window.__PRELOADED_STATE__ = ${transit.toJSON(preloadedState)};
</script>

Client picks up __PRELOADED_STATE__, which is a valid JSON, therefore it is converted to an object. To use it, I need to cast it back to string, e.g.

console.log('window.__PRELOADED_STATE__', transit.fromJSON(JSON.stringify(window.__PRELOADED_STATE__)));

Alternatively, I can stringify the object twice on server: once using transit-immutable-js and second time using JSON.stringify, e.g.

<script>
window.__PRELOADED_STATE__ = ${JSON.stringify(transit.toJSON(preloadedState))};
</script>

Preferably though,transit-immutable-js should be able to accept an object.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
glenjamincommented, Sep 5, 2016

I don’t think it’d be that difficult to create a transit.decoder instance and accept an object without the additional stringify - this issue isn’t currently affecting me so it’s not high up my list of things to do, but I’d definitely take a PR (and help with landing it).

If it does cross my path requirement-wise in the near future I’ll probably tackle it myself.

0reactions
glenjamincommented, Sep 5, 2016

Sorry, I don’t have time to make contributions to new OS projects. Have my hands full.

No worries, I know the feeling!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to pass json object data using Gson? - Stack Overflow
Gson gson = new Gson(); MyProfile obj = new MyProfile(); String jsonInString = gson.toJson(obj); // pass string object to next activity and ...
Read more >
Gson - How to convert Java object to / from JSON - Mkyong.com
In this tutorial, we will show you how to use Gson to convert Java object to / from JSON. P.S All examples are...
Read more >
How to Pass a JSON Object from Child Component to Parent ...
We have one state value, greetingMessage , which can be updated once the user changes the input value and can send it to...
Read more >
Convert Java Object (POJO) To and From JSON with Gson
Convert JSON String to Java Object​​ To reverse this process, and to map a JSON object to a POJO, we'll utilize the fromJson()...
Read more >
Gson - How to convert Java object to / from JSON - YouTube
In this tutorial, we will show you how to use the GSON library to convert Java object to/from JSON.Check out the complete GSON...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found