Allow to pass object to fromJSON
See original GitHub issueUse 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:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
No worries, I know the feeling!