Redux states - do they need to be serializable?
See original GitHub issueIs there any specific reason why KVision’s redux module should require serializable data classes?
I’m running into a problem with a custom class of ObjectID
from MongoDB. I’ve written a custom serializer for my class:
@Serializer(forClass = ObjectID::class)
object ObjectIDSerializer: KSerializer<ObjectID> {
override val descriptor: SerialDescriptor =
StringDescriptor.withName("ObjectID")
override fun serialize(encoder: Encoder, obj: ObjectID) {
encoder.encodeString(obj.toString())
}
override fun deserialize(decoder: Decoder): ObjectID {
return ObjectID(decoder.decodeString())
}
}
but when I try to run it in the browser, I get Can't locate argument-less serializer for class null
even though none of my variables in the redux state are nullable.
Is it possible to remove the requirement for it to be serializable? Unless there is a specific reason why it needs to be.
Issue Analytics
- State:
- Created 4 years ago
- Comments:19 (19 by maintainers)
Top Results From Across the Web
The redux best practice "Do Not Put Non-Serializable Values ...
This article explains one of the four react-redux best practices: "Do Not Put Non-Serializable Values in State or Actions"
Read more >Redux FAQ: Organizing State
It is highly recommended that you only put plain serializable objects, arrays, and primitives into your store. It's technically possible to ...
Read more >Is storing Non-Serializable Values into a Redux store a bad ...
Avoid putting non-serializable values such as Promises, Symbols, Maps/Sets, functions, or class instances into the Redux store state or ...
Read more >About the redux best practice "Do not put non-serializable ...
No, we've always emphasized that a Redux store should only contain plain JS objects, arrays, and primitives, and this article covers some of...
Read more >Storing a function in the Redux store - prasanna.dev
So, if you are trying to store a inside the Redux state, you need to serialize them before persisting. Storing functions inside redux...
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
The redux module is already fixed in my source tree. I’ve modified some tests to check if lists are working and it seems they do. Thx for this enhancement.
First the Redux case. It’s not that simple. The original Redux (redux.js.org) is quite sophisticated piece of software. It’s extendable with addons and middleware and
kvision-redux
module includes one of the most widely used ones: redux-thunk. It allows to dispatch “Action creators” functions, which is necessary for any asynchronous operations. Your redux implementation is very basic and has no support for this. With original Redux implementation you can use any middleware you want, and the Redux ecosystem gives you very large choice. That’s the reason I’ve integrated KVision with original Redux library. I’m watching some Kotlin projects (https://github.com/freeletics/CoRedux, https://github.com/gumil/Kaskade), but none of them are targeting Kotlin/JS yet.Regarding the serializable requirement - the kotlin-redux project I’m using has some limitations with Kotlin Lists. I’ve decided that support for Lists is more important, so my
kvision-redux
module serializes the state to the JSON string before passing it to Redux. This way we can use any classes for the Kotlin state, as long as they are serializable - this is a trade-off.What can be done:
kvision-redux
module without serialization requirement. But you will not be able to use Lists in your state (and should be ready for other incompatibilities).