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.

How to serialize/deserialize a Snoowrap or Listing?

See original GitHub issue

I’m using Snoowrap in a Redux application. I’d love to be able to use redux-persist, but Snoowrap’s objects are not plain-old-JavaScript-objects, so they won’t work with redux-persist. So I have two related questions:

  1. Is there a way to serialize a Snoowrap constructed via Snoowrap.fromAuthCode so that I can reconstruct that object later on?

  2. The same question as (1), but with instances of Listing.

Right now I have to put Listings in my Redux store, and thus my Redux store cannot be serialized into localStorage-friendly form. If instead of putting a Listing in a store, I store an object that I can dynamically convert into a Listing when (for example) I want to fetch more data, then I’d be a happy camper.

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
not-an-aardvarkcommented, Jan 5, 2017

Currently, you can (kind of) serialize a Snoowrap, but you can’t serialize a Listing. I agree that it would be useful to have a way to do this.

(Admittedly annoying) way to serialize a snoowrap in the current version:

const auth = {
  clientId: r.clientId,
  clientSecret: r.clientSecret,
  refreshToken: r.refreshToken,
  // this is all you need for instances from Snoowrap.fromAuthCode in a browser.
  // for snoowraps created with other means, you might also need:
  // userAgent, accessToken, username, password
};

const config = r.config();

// store auth and config somewhere

// later:

const newInstance = new snoowrap(auth);
newInstance.config(config);
1reaction
not-an-aardvarkcommented, Oct 2, 2017

This issue is about serializing snoowrap instances themselves, not reddit content objects created by snoowrap.

It’s true that you can call JSON.stringify on Listing instances, but that won’t preserve some metadata needed to reconstruct them (e.g. the URL for fetching more items).

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to serialize/deserialize a Snoowrap or Listing?
I'm using Snoowrap in a Redux application. I'd love to be able to use redux-persist, but Snoowrap's objects are not plain-old-JavaScript-objects, ...
Read more >
How to serialize and deserialize objects on iOS
If you have a class that you want to serialize or archive, your class will need to implement the 'NSCoding' protocol. The NSCoding...
Read more >
Reddit Api via Snoowrap with Nextjs + TypeScript
// types/json.ts import { Subreddit, Submission, Comment } from 'snoowrap/dist/objects'; export class Serializer<T> { serialize(inp: T): string ...
Read more >
Class: snoowrap - GitHub Pages
Gets a list of all oauth scopes supported by the reddit API. Note: This lists every single oauth scope. To get the scope...
Read more >
How to Serialize Deserialize List of Objects in Java? ...
Java provides a mechanism, called object serialization where an object can be represented as a sequence of bytes that includes the object's ...
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